我对dateformatter有问题。我想解析日期,但我总是早一小时
图片来自http://nsdateformatter.com/,在这里我尝试解析日期中的日期,但我总是提前一个小时。我需要得到18:18:46
,但我总是得到17:18:46
我的代码无效:
extension Date {
func getString() -> String {
var calendar = Calendar.current
calendar.locale = Locale(identifier: Bundle.main.preferredLocalizations[0])
let dateFormatter = DateFormatter()
dateFormatter.calendar = calendar
dateFormatter.timeZone = TimeZone.current
dateFormatter.dateFormat = "d.M.yyyy, HH:mm:ss"
return dateFormatter.string(from: self)
}
}
谢谢您的回答。