- (void)viewDidLoad {
[super viewDidLoad];
NSDate *date = [NSDate date];
NSLog(@"%@", date);
}
//控制台输出:
//2016-07-27 22:21:19.082 projectName[14137:701546] 2016-07-27 14:21:19 +0000
//可以看到本地时间与GMT标准时间差了8小时
- (void)viewDidLoad {
[super viewDidLoad];
NSTimeZone *zone = [NSTimeZone systemTimeZone];//获得系统的时区
NSDate *date = [NSDate date]; //获得时间对象
NSTimeInterval time = [zone secondsFromGMTForDate:date]; //返回当前时间与系统格林尼治时间的差(以秒为单位)
NSDate *localDate = [date dateByAddingTimeInterval:time];//然后把差的时间加上,就是当前系统准确的时间}
NSLog(@"%@", localDate);
}
//控制台输出:
//2016-07-27 22:23:14.673 projectName[14150:703293] 2016-07-27 22:23:14 +0000