iphone - 通过 iPhone SDK 确定东海岸当前使用的是 EST 还是 EDT

标签 iphone cocoa

如何使用 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/

相关文章:

ios - quickblox webrtc视频通话接收方法未被调用

iPhone应用程序 : How do they do that?

iphone - 如何更新 NSUserDefault

ios - 为 iPhone 6s 编译和较旧的应用程序显示较低的分辨率

iphone - 1 台设备上的多个推送通知 - iPhone

iphone - 如何为 AVAudioPlayer 制作安全的 mp3 文件,而不会出错

objective-c - Obj-c/Cocoa 中的互斥锁

macos - 更改边界原点+裁剪图像

objective-c - 使用 Cocoa Frameworks 时的 MacRuby 指针、引用、取消引用

IOS:获取具有特定(非本地化)格式的当前日期/时间