66

我系统的日期时间是 5 月 26 日 22:55,但是当我得到日期[NSDate date]时间是 5 月 27 日 02:35

是因为时区吗?

如果是,如何解决这个问题,当我得到日期时间时,给我系统的日期并且不检查时区

4

1 回答 1

147
NSLocale* currentLocale = [NSLocale currentLocale];
[[NSDate date] descriptionWithLocale:currentLocale];  

或使用

NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
// or @"yyyy-MM-dd hh:mm:ss a" if you prefer the time with AM/PM 
NSLog(@"%@",[dateFormatter stringFromDate:[NSDate date]]);
于 2012-05-27T06:14:13.890 回答