user1079052
user1079052

Reputation: 3843

ISO 8601 Date Formatter in Objective for iPhone not setting offset correctly

Thank you in advance for you help.

I am trying to create a ISO 8601 date formatter for my iPhone application and I can not get the offset to come out correctly. I need the result time zone to be in GMT and I am located in EST and when I tested it at 2:33 PM March 6th 2012 I got 2012-03-06T14:33:35+0000

Due to the zone difference I need -05:00 to show up instead of +0000

The code I am using is:

            NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss ZZ"];
            NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
            [dateFormatter setTimeZone:gmt];

            NNSDate *gmtDate  = [[NSDate alloc] init];
            dateString = [dateFormatter stringFromDate:gmtDate];

            NSLog(@"Date String: %@", dateString);

Upvotes: 0

Views: 486

Answers (1)

JeremyP
JeremyP

Reputation: 86691

Have you tried setting the time zone to EST? That will probably give you your -0500

Upvotes: 2

Related Questions