gpt4 book ai didi

ios - Nsdateformatter + 时区问题

转载 作者:行者123 更新时间:2023-12-01 17:41:20 27 4
gpt4 key购买 nike

我正在尝试解析这个日期时间戳
开始串:

Wed, 11 Sep 2013 08:51:41 EEST



这个问题只有

EEST



, 我试过 z 或 zzz 或 V,什么也没发生。日期格式化程序始终为 NULL。

当我从字符串中删除 EEST 时,一切正常。

任何人都可以建议,如何解决这个问题?

谢谢

更新:
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_EN_POSIX"]];
[dateFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"EEST"]];
[dateFormat setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss V"];
dateFromString = [dateFormat dateFromString:beginString];

最佳答案

您对这个问题的解决方案是将语言环境更改为 en_GB并且日期格式化程序将能够正确解析您的日期字符串。
这是 Apple 开发人员错误报告团队对 radar #9944011 的回复的解释。 :

This is an intentional change in iOS 5. The issue is this: With the short formats as specified by z (=zzz) or v (=vvv), there can be a lot of ambiguity. For example, "ET" for Eastern Time" could apply to different time zones in many different regions. To improve formatting and parsing reliability, the short forms are only used in a locale if the "cu" (commonly used) flag is set for the locale. Otherwise, only the long forms are used (for both formatting and parsing). This is a change in open-source CLDR 2.0 / ICU 4.8, which is the basis for the ICU in iOS 5, which in turn is the basis of NSDateFormatter behavior.

For the "en" locale (= "en_US"), the cu flag is set for metazones such as Alaska, America_Central, America_Eastern, America_Mountain, America_Pacific, Atlantic, Hawaii_Aleutian, and GMT. It is not set for Europe_Central.

However, for the "en_GB" locale, the cu flag is set for Europe_Central.

So, a formatter set for short timezone style "z" or "zzz" and locale "en" or "en_US" will not parse "CEST" or "CET", but if the locale is instead set to "en_GB" it will parse those. The "GMT" style will be parsed by all.

If the formatter is set for the long timezone style "zzzz", and the locale is any of "en", "en_US", or "en_GB", then any of the following will be parsed, because they are unambiguous:

"Pacific Daylight Time" "Central European Summer Time" "Central European Time"

关于ios - Nsdateformatter + 时区问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18763420/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com