【问题标题】:Parsing BST Timezone解析 BST 时区
【发布时间】:2012-04-28 00:47:44
【问题描述】:

我在解析时区为“BST”的日期时遇到问题。

这是日期:2012-04-22 16:00:00 BST

这是我的代码

NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
NSDate * matchDate = [formatter dateFromString:dateStr];

例如,这适用于 GMT,但对于 BST,我得到了零,有什么线索吗?

【问题讨论】:

  • 你能发布准确的输入字符串示例吗?

标签: objective-c ios timezone nsdateformatter


【解决方案1】:

BST 是一种日期格式,被视为metazone,因此您应该使用V 语法对其进行解析。

我建议将您的解析字符串更改为:

[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss V"];

在 ZZZ 周围使用引号,意味着解析器应该期待 文本 ZZZ,而不是时区

【讨论】:

  • 非常感谢,不知道那些 Metazones!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-29
  • 1970-01-01
  • 2010-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多