我正在尝试通过添加设备时区获取当前日期,但是在原始日期晚1小时显示.我的事,我遇到了DaylightSavingTime的问题.如何禁用isDaylightSavingTime = FALSE.
这是代码,我用过..
NSDate *date = [NSDate Date];
NSTimeZone *currentTimeZon = [NSTimeZone localTimeZone];
if ([currentTimeZon isDaylightSavingTime])
{
NSLog(@"East coast is NOT on DT");
}
else
{
NSLog(@"East coast is on DT");
}
NSTimeInterval timeZoneOffset = [currentTimeZon secondsFromGMTForDate:currentDate];
NSTimeInterval gmtTimeInterval = [date timeIntervalSinceReferenceDate] - timeZoneOffset;
NSDate *gmtDate = [NSDate dateWithTimeIntervalSinceReferenceDate:gmtTimeInterval];
NSLog(@"### Announcement gmtDate = %@",gmtDate);
Run Code Online (Sandbox Code Playgroud)
我有时间与1小时的差异,日期是完美的.
| 归档时间: |
|
| 查看次数: |
1084 次 |
| 最近记录: |