Can you override NSDateFormatter 12 vs 24 hour time format without using a custom dateFormat

前端 未结 1 461
没有蜡笔的小新
没有蜡笔的小新 2021-01-26 03:54

I want to convert a Date as a display string in the user\'s time zone, but I want to use 24 hour time format rather than 12 hour time format.

I know I can do that by exp

1条回答
  •  醉话见心
    2021-01-26 04:47

    DateFormatter has the dateFormat(fromTemplate:options:locale:) method. Use this to get a proper 24-hour format based on the user's locale.

    let fmt = DateFormatter.dateFormat(fromTemplate: "Hms", options: 0, locale: Locale.current)
    

    Though this seems to return HH:mm:ss for most locales. Only 85 of the 739 available locales return something other than HH:mm:ss.

    0 讨论(0)
提交回复
热议问题