let estDf = DateFormatter()
let gmtDf = DateFormatter()
gmtDf.timeZone = TimeZone(identifier: "UTC")
gmtDf.dateFormat = "yyyy-MM-dd','HH:mm:ss"
let time_ = "2017-10-21,10:53:23"
let utcDate = gmtDf.date(from: time_)!
print("UTC :",utcDate)
let timeZone = TimeZone.autoupdatingCurrent.identifier as String
estDf.timeZone = TimeZone(identifier: timeZone)
estDf.dateFormat = "yyyy-MM-dd','HH:mm:ss"
let estDate = estDf.date(from: gmtDf.string(from: utcDate))!
print("Local time",estDate)
从UTC时间格式转换为本地时间格式时,时间显示在一小时后。
因此,如果UTC时间是
2017-10-21 10:53:23 +0000
当地时间显示为
2017-10-21 10:53:23 +0000
但设备中的实际时间是:
2017-10-21 9:53:23 +0000