0

我正在制作复杂功能,并希望在复杂功能中使用 24 小时格式显示“UTC”时区时间。

CLKTimeTextProvider 可以工作,但它似乎只使用用户喜欢的默认格式,而我需要强制它始终显示 24 小时制。

有什么想法吗?有没有我看不到的属性?

switch family {            
case .UtilitarianLarge:
        let template = CLKComplicationTemplateUtilitarianLargeFlat()
        template.imageProvider = nil
        template.textProvider = CLKTimeTextProvider(date: NSDate(), timeZone: NSTimeZone(name: "UTC"))
        return CLKComplicationTimelineEntry(date: date, complicationTemplate: template)
4

1 回答 1

0

目前没有任何CLKTimeTextProvider属性可以让您覆盖用户的区域和语言环境设置。

除了提交功能请求之外,您还可以通过将日期转换为 24 小时格式的时间来解决该问题,然后使用CLKSimpleTextProvider

let dateFormatter = NSDateFormatter()
let localeFormatString = NSDateFormatter.dateFormatFromTemplate("HH:mm", options: 0, locale: NSLocale.currentLocale())
dateFormatter.dateFormat = localeFormatString
dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC")
template.textProvider = CLKSimpleTextProvider(text: dateFormatter.stringFromDate(NSDate()))

更新:

根据您的评论,您可以使用CLKRelativeDateStyleTimer从午夜 00:00 开始计数的 a 来完成您想要的操作。由于它正在计算小时和分钟,因此它会以 24 小时格式进行计数。您必须在午夜更新您的并发症,以便在第二天将其重置为 00:00。

于 2016-03-22T22:15:11.040 回答