简体   繁体   English

以24小时格式显示特定时区的并发症当前时间

[英]Display complication current time in 24 hour format for specific timezone

I am making a complication, and want to display "UTC" timezone time using 24-hour format in the complication. 我正在做一个并发症,并希望在并发症中使用24小时格式显示“ UTC”时区时间。

CLKTimeTextProvider will work, but it seems to only use the default format the user prefers, whereas I need to force it to always show 24-hour time. CLKTimeTextProvider可以工作,但是它似乎仅使用用户喜欢的默认格式,而我需要强制使其始终显示24小时制。

Any thoughts? 有什么想法吗? Is there a property I am not seeing? 有没有我没看到的财产吗?

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)

There's no CLKTimeTextProvider property that would currently let you override the user's region and locale settings. 当前没有CLKTimeTextProvider属性,该属性使您可以覆盖用户的区域和区域设置。

Apart from submitting a feature request , you could workaround the issue by converting the date to a 24-hour formatted time, then display that localized string using a CLKSimpleTextProvider 除了提交功能请求外 ,您还可以通过将日期转换为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()))

Update: 更新:

Based on your comments, you might be able to accomplish what you want by using a CLKRelativeDateStyleTimer which counted up from 00:00 midnight. 根据您的评论,您可以使用CLKRelativeDateStyleTimer来完成CLKRelativeDateStyleTimer ,该CLKRelativeDateStyleTimer从午夜00:00开始计时。 Since it's counting up hours and minutes, it would happen to count up in 24-hour format. 由于它是在计算小时和分钟,因此它会以24小时制进行计数。 You would have to update your complication at midnight, to reset it to 00:00 for the next day. 您将必须在午夜更新并发症,以将其重置为第二天的00:00。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM