gpt4 book ai didi

ios - 系统时区与选定时区

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:08:59 27 4
gpt4 key购买 nike

What's the best way to compare two time zones?

我在使用 - (BOOL)isEqualToTimeZone:(NSTimeZone *)aTimeZone 方法比较两个 NSTimeZone 实例时遇到问题。

NSString *timeZoneName = ...

NSTimeZone *sytemTimeZone = [NSTimeZone systemTimeZone];
NSTimeZone *selectedTimeZone = [NSTimeZone timeZoneWithName:timeZoneName];

if ([sytemTimeZone isEqualToTimeZone:selectedTimeZone])
isEqual = YES;
else
isEqual = NO;

第 1 步:转到“设置(应用程序)”>“常规”>“日期和时间”>“时区”并搜索“Austin”。您将获得的条目将是“美国奥斯汀”。选择这个时区。现在这应该是您的新系统时区!

第 2 步:创建一个小型 iPhone/iPad 应用程序。使用 [NSTimeZone knownTimeZoneNames] 获取时区名称列表。然后尝试找到“Austin”。它不在那里!所以,我想我们可以使用“美国/芝加哥”作为时区吗?

Why is the Setting's timezone list different from ours?

第 3 步: 现在将系统时区与“美国/芝加哥”时区进行比较。它们不匹配。

最佳答案

我为此发布了一个错误 - 该错误是奥斯汀不在已知时区列表中,但由设置应用程序提供。

根据 Apple 工程师的说法:

For two NSTimeZones to compare equal, both the names and the data (as returns by -data) must be equal. You have to be careful when comparing time zones, because two zones can have the same offset from GMT but not be the same time zone for historical reasons. Remember that time zones are used for all sorts of calendrical calculations, meaning that they are only equal if, throughout history, they've always had the same GMT offset, the same daylight savings transitions, and so on.

关于ios - 系统时区与选定时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7885468/

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