我正在尝试使用以下代码将 UNIX epoc 时间转换为日期时间格式
var epocTime = NSTimeInterval(1429162809359)
let myDate = NSDate(timeIntervalSince1970: epocTime)
println("Converted Time \(myDate)")
实际结果是(星期四,2015 年 4 月 16 日 05:40:09 GMT),但我得到的结果类似于 (47258-05-14 05:15:59 +0000) 谁能告诉我如何实现这一点。
最佳答案
更新:Xcode 8.2.1 • Swift 3.0.2 或更高版本
您需要将它从毫秒除以 1000 转换为:
let epochTime = TimeInterval(1429162809359) / 1000
let date = Date(timeIntervalSince1970: epochTime) // "Apr 16, 2015, 2:40 AM"
print("Converted Time \(date)") // "Converted Time 2015-04-16 05:40:09 +0000\n"
关于swift - 如何在 ios swift 中将 UNIX 纪元时间转换为日期和时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29670585/