1. Code.
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //Get the current time [self currentTime]; } #pragma -mark -functions //Calculate the current time- (void)currentTime { //Time format NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; //The current time NSDate * currentdate = [NSDate date]; NSString * currentDateString = [dateFormatter stringFromDate: currentdate]; NSLog(@"---currentDateString--%@",currentDateString); }
2. Output.
2015-10-23 10:15:24.928 Calculate the current time[1607:61610] ---currentDateString--2015-10-23 10:15:24
The above is the time code for iOS that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!