0
点赞
收藏
分享

微信扫一扫

iOS NSDateFormatter遇到的问题

boom莎卡拉卡 2021-09-23 阅读 34
//获取系统当前时间
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;

以上

举报

相关推荐

0 条评论