在不使用时间的情况下获取 AM / PM 的时间格式化字符串

问题描述 投票:0回答:1

有没有办法从时间格式化程序获取 AM / PM 本地化字符串而不使用任何给定时间?

类似:

let locale = Locale(identifier: "en-us")
        
let formatter = DateFormatter()
formatter.locale = locale
formatter.dateFormat = "a"

并以某种方式打印“am”和“pm”变体。

swift datetime-format
1个回答
1
投票

您可以使用

Calendar
amSymbol
 属性从 
pmSymbol
获取它。

var calendar = Calendar.current
// set the locale if you want am/pm for a non-current locale
// calendar.locale = someLocale
let am = calendar.amSymbol
let pm = calendar.pmSymbol
© www.soinside.com 2019 - 2024. All rights reserved.