ios – 需要打印信息[NSDate日期]

当我打印日期时
//getting the current date and time
self.date = [NSDate date];
NSLog(@"%@",date);

我得到的日期是正确的,但是时间延迟了6小时.我的系统时间是正确的.

解决方法

使用NSDateFormatter
NSDate *today = [NSDate date];

//Create the dateformatter object
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

//Set the required date format
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

//Get the string date
NSString *dateString = [dateFormatter stringFromDate:today];

//Display on the console
NSLog(dateString);

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...