Get Unix Epoch Time in Swift

For Swift 3.0

Date().timeIntervalSince1970

You can get that using following

Int(Date().timeIntervalSince1970)

This is for current date, if you want to get for a given date

Int(myDate.timeIntervalSince1970)

If you want to convert back from UNIX time epoch to Swift Date time, you can use following

let date = Date(timeIntervalSince1970: unixtEpochTime)

You can simply use NSDate's timeIntervalSince1970 function.

let timeInterval = NSDate().timeIntervalSince1970

Tags:

Time

Swift