Swift – Current Date and Time

To get current date and time in Swift, import Foundation, and initialize a Date value. Date value has a description property, through which we can get the textual description of the date value.

The syntax to get the current date and time using Date is

</>
Copy
import Foundation

let date = Date()
var x = date.description

Of course, the date and time we get are the UTC +0 or Greenwich Mean Time.

Example

In the following example, we will get the current date and time and print it to output.

main.swift

</>
Copy
import Foundation

let date = Date()
var x = date.description
print(x)

Output

Swift - Current Date and Time

Conclusion

In this Swift Tutorial, we learned how to get Current Date and Time in Swift using Date.