Mobile App Dev Diary

Android (Java, Kotlin), iOS (Swift), Xamarin (C#)

Swift 3.0 / Convert String to Unix Timestamp

Convert String to Unix Timestamp in Swift version 3.0.

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let dateString = "1970-01-01 09:00:00"
let date:Date? = dateFormatter.date(from: dateString)
let dateUnix: TimeInterval? = date?.timeIntervalSince1970

Related entry:

python.hatenablog.jp

Remove all ads