Skip to content

Instantly share code, notes, and snippets.

@miharekar
Created December 27, 2012 08:57
Show Gist options
  • Save miharekar/4386699 to your computer and use it in GitHub Desktop.
Save miharekar/4386699 to your computer and use it in GitHub Desktop.
Simple way to get GMT date from ISO8601 date in Objective C
- (NSString *)getGMTDateStringfromISO8601DateString:(NSString *)ISODateString
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];
ISODateString = [ISODateString stringByReplacingOccurrencesOfString:@":" withString:@"" options:0 range:NSMakeRange([ISODateString length]-5, 5)];
NSDate *ISODate = [formatter dateFromString:ISODateString];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
return [formatter stringFromDate:ISODate];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment