iOS get current date and time

It is simple to get current date and time, Apple Developer have a Class named NSDate, bravo!! Besides, function dateFormat can format the date and time, awesome. Finally, using the setTimeZone function to set timezone.

NSDate *now = [NSDate date];
NSDateFormatter *currentTime = [[NSDateFormatter alloc] init];

currentTime.dateFormat = @"yyyy:mm:dd:hh:mm:ss";
[currentTime setTimeZone:[NSTimeZone systemTimeZone]];

NSLog(@"time:%@",[currentTime stringFromDate:now]);

0 意見: