假设我在本地时间有一个字符串:“Apr 14, 2015, 8:53 AM”。如何将其转换为正确的 UTC 时间?
Best Answer-推荐答案 strong>
试试这样:
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/
|