HH日期格式生成个位数小时

时间:2019-03-18 10:50:55

标签: ios swift date locale nsdateformatter

我正在使用yyyy-MM-dd'T'HH:mm:ssZ日期格式将时间戳记值转换为日期字符串。下面是我这样做的代码:

let date = Date(timeIntervalSince1970: Double(myTimeStampInInt64))
let dateFormatter = DateFormatter.init()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
dateFormatter.timeZone = TimeZone.current
dateFormatter.locale = Locale.current
dateFormatter.calendar = Calendar(identifier: .gregorian)
let isoDateString = dateFormatter.string(from: date)

大多数时候,我会使用2位数小时的24小时格式。有时我的用户以12小时格式获得单位数小时,有时获得单位数小时。 我得到的响应是2018-08-07T3:38:55-0500。 任何线索如何发生?是否有任何指导原则Locale.current会导致此问题?

0 个答案:

没有答案