Created
July 2, 2013 10:51
-
-
Save fabb/5908388 to your computer and use it in GitHub Desktop.
format current NSDate as ISO8601 string despite user's Calendar or 24-Hour-Format setting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)currentGregorianISO8601Date { | |
NSDate *requestDate = [NSDate date]; | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; | |
// WORKAROUND http://openradar.appspot.com/radar?id=1110403 | |
[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]; | |
NSLog(@"%@",dateString); | |
return dateString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment