//获取系统当前时间
NSDate*currentDate=[NSDatedate];
//用于格式化NSDate对象
NSDateFormatter*dateFormatter=[[NSDateFormatteralloc]init];
//设置格式:zzz表示时区
[dateFormattersetDateFormat:@"yyyy-MM-ddHH:mm:sszzz"];
//NSDate转NSString
NSString*currentDateString=[dateFormatterstringFromDate:currentDate];
//输出currentDateString
NSLog(@"%@",currentDateString);
以上大家觉得没问题吧, 但是你随便搞搞语言12小时制就完蛋了
于是求了求李彦宏~
解决办法如下
NSLocale*usLocale=[[NSLocalealloc]initWithLocaleIdentifier:@"en_US"];
dateFormatter.locale=usLocale;
以上