tags:

views:

56

answers:

2

How can I determine if the east coast is currently using EST or EDT using the iPhone SDK?

I am aware of the NSTimeZone class and I attempted the following but it did not work, the result is "East coast is NOT on DT" which it currently is. This leads me to believe that isDayLightSavingTime simply checks whether its being passed an ST or DT value rather than determining if EST should currently be EDT

NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"EST"];
if ([easternTimeZone isDaylightSavingTime]) {
    NSLog(@"East coast is NOT on DT");
} else {
    NSLog(@"East coast is on DT");      
}

UPDATE:

The end goal is I need to be able to calculate the correct current time in the eastern timezone, taking into account whether they are currently observing daylight savings time.

UPDATE 2:

Interesting result, when I change

NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"EST"];

to

NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"EDT"];

it still returns "East Coast is NOT on DT"

+2  A: 

Use US/Eastern instead.

NSTimeZone *easternTimeZone = [NSTimeZone timeZoneWithName:@"US/Eastern"];
if ([easternTimeZone isDaylightSavingTime]) {
    NSLog(@"East coast is NOT on DT");
} else {
    NSLog(@"East coast is on DT");      
}

Note that you need to use -[NSTimeZone timeZoneWithName:], instead of -[NSTimeZone timeZoneWithAbbreviation:]

Yuji
+2  A: 

Are you sure this isn't just a bug in your logging?

You're checking for [easternTimeZone isDaylightSavingTime] and if it's true you're logging @"East coast is NOT on DT". It appears that the logic is correct, as this is the result you're getting, you're just logging it the wrong way...

Mo
Yep, thanks Mo, simple overlook
Flash84x