Created
December 4, 2012 16:12
-
-
Save jdewind/4205653 to your computer and use it in GitHub Desktop.
ISO8601 Formatter enforcing Locale
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
@implementation NSDateFormatter(Extensions) | |
+ (NSDateFormatter *)apiFriendlyDateFormatter { | |
static NSDateFormatter *_utcFormatter; | |
if (!_utcFormatter) { | |
_utcFormatter = [[NSDateFormatter alloc] init]; | |
NSLocale *enUSPOSIXLocal = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]; | |
[_utcFormatter setLocale:enUSPOSIXLocal]; | |
[_utcFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT: 0]]; | |
[_utcFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"]; | |
} | |
return _utcFormatter; | |
} | |
@end |
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
@implementation NSDateFormatter(Extensions) | |
+ (NSDateFormatter *)apiFriendlyDateFormatter { | |
static NSDateFormatter *utcFormatter = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
utcFormatter = [[NSDateFormatter alloc] init]; | |
NSLocale *enUSPOSIXLocal = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]; | |
[utcFormatter setLocale:enUSPOSIXLocal]; | |
[utcFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT: 0]]; | |
[utcFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"]; | |
}); | |
return utcFormatter; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment