ios - 时区缩写不以两位数格式返回

标签 ios swift timezone

TimeZone.current.abbreviation() 

它将返回 GMT+5:30 ,我的要求是将其设置为 GMT+05:30

最佳答案

如果您需要特定格式的当前时区,一种方法是以某种非正统的方式使用 DateFormatter:

// formatter.timeZone is implicitly TimeZone.current
let formatter = DateFormatter()
formatter.dateFormat = "ZZZZ"

let abbreviation = formatter.string(from: Date())

这将返回一个“GMT±xx:yy”形式的字符串;对我来说,这是“GMT-07:00”。

请参阅Date Field Symbol Table from TR35-31了解更多信息。

关于ios - 时区缩写不以两位数格式返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49542254/

相关文章:

ios - 场景的子元素发布速度不够快?

swift - 如何在 Swift 2.0 中将 HKQuanity 转换为 Int

c# - TimeZoneInfo.ConvertTime 在 DateTime.MinValue 上非常慢

java - 日历 : set TimeZone correctly

javascript - UIWebview 使用 javascript 在移动 safari 中打开 URL

ios - 是否可以在 iOS 中的所有应用程序的屏幕信息上访问电池使用情况/时间?

ios - 使用 UINavigationController navigationItem -> rightBarButtonItem

ios - AUVoiceProcessing 单元 kAUVoiceIOProperty_VoiceProcessingQuality 弃用

ios - 有什么方法可以通过 NFC 传输字符串吗?

python - Django raw sql/postgres 时区混淆