iOS:我应该使用EST或EDT,为什么?

Wil*_*lex 1 timezone objective-c ios

我不久前问了一个关于时区的问题,我正在使用EST.用户建议我使用EDT.我想知道为什么我应该使用其中一个,因为它们都为我打印同一时间.这是代码,以更好地说明我的意思.

NSDate *today = [NSDate date];
NSDateFormatter *edtDf = [[NSDateFormatter alloc] init];
[edtDf setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"EDT"]];
[edtDf setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSString *stringDate = [edtDf stringFromDate:today];

NSLog(@"The EDT is %@", stringDate);

NSDate *today1 = [NSDate date];
NSDateFormatter *estDf = [[NSDateFormatter alloc] init];
[estDf setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"EST"]];
[estDf setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSString *stringDate1 = [estDf stringFromDate:today1];

NSLog(@"The EST is %@", stringDate1);
Run Code Online (Sandbox Code Playgroud)

rob*_*off 6

他们可能会根据一年中的时间打印不同的东西(因为时间确定夏令时是否有效).

不要使用EST EDT.使用US/EasternAmerica/New_York:

NSTimeZone *tz = [NSTimeZone timeZoneWithName:@"US/Eastern"];
// or
NSTimeZone *tz = [NSTimeZone timeZoneWithName:@"America/New_York"];
Run Code Online (Sandbox Code Playgroud)

这些时区会在一年中的正确时间调整夏令时.