假设我在本地时间有一个字符串:“Apr 14, 2015, 8:53 AM”。如何将其转换为正确的 UTC 时间?
试试这样:
let dateString = "Apr 14, 2015, 8:53 AM"
let df = NSDateFormatter()
df.dateFormat = "LLL DD, yyyy, h:mm a"
if let dateFromString = df.dateFromString(dateString){
print(dateFromString) // "2015-01-14 10:53:00 +0000\n"
df.timeZone = NSTimeZone(forSecondsFromGMT: 0)
let stringFromDate = df.stringFromDate(dateFromString) //"Jan 14, 2015, 10:53 AM"
}
关于ios - 如何在 Swift 中将本地时间的日期转换为 UTC?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36631232/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |