如何使用 iPhone SDK 确定东海岸当前使用的是 EST 还是 EDT?
我知道 NSTimeZone 类,并且我尝试了以下操作,但它不起作用,结果是“东海岸不在 DT 上”,而它目前是。这让我相信 isDayLightSavingTime 只是检查是否传递了 ST 或 DT 值,而不是确定 EST 当前是否应该为 EDT
NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"EST"];
if ([easternTimeZone isDaylightSavingTime]) {
NSLog(@"East coast is NOT on DT");
} else {
NSLog(@"East coast is on DT");
}
更新:
最终目标是我需要能够计算东部时区的正确当前时间,同时考虑到他们当前是否遵守夏令时。
更新2:
当我改变时,有趣的结果
NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"EST"];
到
NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"EDT"];
它仍然返回“东海岸不在 DT 上”
最佳答案
改用美国/东部
。
NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithName:@"US/Eastern"];
if ([easternTimeZone isDaylightSavingTime]) {
NSLog(@"East coast is NOT on DT");
} else {
NSLog(@"East coast is on DT");
}
请注意,您需要使用-[NSTimeZone timeZoneWithName:]
,而不是-[NSTimeZone timeZoneWithAbbreviation:]
关于iphone - 通过 iPhone SDK 确定东海岸当前使用的是 EST 还是 EDT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3154306/