无法在Swift中将时间间隔158948565000转换为日期
看起来是1970年以来的毫秒数。所以你需要把你的值除以1000。您使用了错误的初始值设定项无法在Swift中将时间间隔158948565000转换为日期,swift,Swift,看起来是1970年以来的毫秒数。所以你需要把你的值除以1000。您使用了错误的初始值设定项timeintervalnceReferenceDate是“日期对象与2001年1月1日00:00:00 UTC之间的间隔” 看起来是1970年以来的毫秒数。所以你需要把你的值除以1000。您使用了错误的初始值设定项timeintervalnceReferenceDate是“日期对象与2001年1月1日00:00:00 UTC之间的间隔” 我刚刚得到了与Xcode 11.5中的代码完全相同的“52369/1
timeintervalnceReferenceDate
是“日期对象与2001年1月1日00:00:00 UTC之间的间隔”
看起来是1970年以来的毫秒数。所以你需要把你的值除以1000。您使用了错误的初始值设定项
timeintervalnceReferenceDate
是“日期对象与2001年1月1日00:00:00 UTC之间的间隔”
我刚刚得到了与Xcode 11.5中的代码完全相同的“52369/10/17 13:03:20 PM”
。我刚刚得到了与Xcode 11.5中的代码完全相同的“52369/10/17 13:03:20 PM”
。
let date = Date(timeIntervalSinceReferenceDate: 1589485565000)
let formatter = DateFormatter() formatter.dateFormat = "yyyy/MM/dd HH:mm:ss a"
let myString = formatter.string(from: date)
let date = Date(timeIntervalSince1970: Double(1589485565000) / 1000 )
let formatter = DateFormatter()
formatter.locale = .init(identifier: "en_US_POSIX")
formatter.dateFormat = "yyyy/MM/dd HH:mm:ss a"
let string = formatter.string(from: date) // "2020/05/14 16:46:05 PM"