anonymous / main.m
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Contrived Date Example

View main.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#import <Foundation/Foundation.h>
 
int main(int argc, const char * argv[])
{
 
@autoreleasepool {
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"YYYY/MM/dd hh:mm:ss"];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setYear:2012];
[components setMonth:12];
[components setDay:31];
NSDate *nye = [gregorian dateFromComponents:components];
NSString *dateStr = [df stringFromDate:nye];
NSLog(@"NYE: %@", dateStr);
 
NSDate *now = [NSDate date];
[df setDateFormat:@"yyyy/MM/dd hh:mm:ss"];
NSDate *reconstitutedDate = [df dateFromString:dateStr];
NSLog(@"NYE: %@", reconstitutedDate);
}
return 0;
}
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.