如何使用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");
}
Run Code Online (Sandbox Code Playgroud)
更新:
最终目标是我需要能够计算东部时区的正确当前时间,同时考虑到他们目前是否正在观察夏令时.
更新2:
有趣的结果,当我改变
NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"EST"];
至
NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"EDT"];
它仍然返回"东海岸不在DT"
请US/Eastern改用.
NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithName:@"US/Eastern"];
if ([easternTimeZone isDaylightSavingTime]) {
NSLog(@"East coast is NOT on DT");
} else {
NSLog(@"East coast is on DT");
}
Run Code Online (Sandbox Code Playgroud)
请注意,您需要使用-[NSTimeZone timeZoneWithName:]而不是-[NSTimeZone timeZoneWithAbbreviation:]
| 归档时间: |
|
| 查看次数: |
1434 次 |
| 最近记录: |