Skip to content

Instantly share code, notes, and snippets.

@fabb fabb/gist:5908388
Created Jul 2, 2013

What would you like to do?
format current NSDate as ISO8601 string despite user's Calendar or 24-Hour-Format setting
- (NSString *)currentGregorianISO8601Date {
NSDate *requestDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"US"]];
// translate to Gregorian calendar if other calendar is selected
NSCalendar * gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[gregorian setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
[dateFormatter setCalendar:gregorian];
NSString *dateString = [dateFormatter stringFromDate:requestDate];
return dateString;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.