Last active
October 30, 2020 16:45
-
-
Save software-mariodiana/132c579bc1d56caab74a174d8edeea2a to your computer and use it in GitHub Desktop.
Category on NSDate to print timestamp in ISO-8601 format.
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
#import <Foundation/Foundation.h> | |
@interface NSDate (ISO8601) | |
- (NSString *)mdx_canonicalTimestamp; | |
@end | |
@implementation NSDate (ISO8601) | |
- (NSString *)mdx_canonicalTimestamp | |
{ | |
static NSISO8601DateFormatter* formatter; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
formatter = [[NSISO8601DateFormatter alloc] init]; | |
formatter.formatOptions = NSISO8601DateFormatWithInternetDateTime; | |
}); | |
return [formatter stringFromDate:self]; | |
} | |
@end | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
NSDate* now = [NSDate date]; | |
NSLog(@"%@", [now mdx_canonicalTimestamp]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment