Last active
August 12, 2018 18:22
-
-
Save nishabe/a3cae37e61ef4df47a9149ff87b2f6d4 to your computer and use it in GitHub Desktop.
OBJC: Date Formatter Sample
This file contains hidden or 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
NSDate to NSString: | |
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"yyyy-MM-dd"]; | |
NSDate* myDate = [NSDate date]; | |
NSString *stringFromDate = [dateFormatter stringFromDate:myDate]; | |
NSString to NSDate: | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"]; | |
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; | |
NSDate *sapTimestamp = [dateFormatter dateFromString:@"2015-05-08 23:36:30 +0000"]; | |
NSLog(@"%@",[dateFormatter stringFromDate:sapTimestamp]); | |
//OP:2015-05-08 23:36:30 +0000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment