iOS NSDate获取当前时间并格式化

 NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
 NSString *dateTime = [formatter stringFromDate:[NSDate date]];
NSLog(@"formatted time is: %@",dateTime);

  

 NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:date];
 NSDate *localDate = [date dateByAddingTimeInterval:interval];
NSLog(@"localtime is:%@",localDate);

  

Stay hungry,stay foolish.
原文地址:https://www.cnblogs.com/ficow/p/5040780.html