【发布时间】:2018-03-09 12:36:19
【问题描述】:
我有 yyyy-MM-ddTHH:mm:ssZ 格式的 CEST 日期。我想以本地格式显示它们。以下功能工作正常。它正确显示时间。 但最后我不得不以 "dd.MM.yyyy HH:mm" 格式显示日期。如何从 iOS 获取本地/本地 DateFormat。
func changeTime()
{
myLabel.text = convertTimeZoneToLocal(timeZone: "CEST", date: "2017-09-27T18:25:42Z")
}
func convertTimeZoneToLocal(timeZone:String, date:String) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
dateFormatter.timeZone = TimeZone(abbreviation: timeZone)
let dt = dateFormatter.date(from: date)
dateFormatter.timeZone = TimeZone.current
dateFormatter.dateFormat = "dd.MM.yyyy HH:mm" // I want to change this line.
return dateFormatter.string(from: dt!)
}
【问题讨论】: