iOS 10错误?日本地区的NSDate小时描述和24小时休息时间 [英] iOS 10 bug? NSDate hour description with Japan region and 24-Hour Time off

查看:27
本文介绍了iOS 10错误?日本地区的NSDate小时描述和24小时休息时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个iOS 10错误.在iOS 8和9中可以.

This seems like an iOS 10 bug. It is OK in iOS 8 and 9.

[NSDate date] .description的小时描述不正确.它附加了24小时描述和12小时描述.我没有使用NSDateFormatter.只是默认设置.

The hour description is wrong for [NSDate date].description. It is appending the 24 hour description and 12 hour description. I am not using NSDateFormatter. Just the default settings.

在真实的iOS 10设备上,在设置"中:

On a real iOS 10 device, in Settings:

  • 在设置">常规">语言和语言"中将地区设置为日本.区域>区域格式>区域
  • 在设置">常规">日期和时间"中将"24小时制"设置为关闭".时间> 24小时时间

然后使用:

NSLog(@"Date is %@", [NSDate date].description);

实际日志输出:

Date is 2016-11-14 44:14:57 AM +0000

预期输出:

Date is 2016-11-14 4:14:57 AM +0000

编辑(添加另一个示例):

Edit (Adding another example):

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd hh:mm:ss a";
NSString *dateString = @"1985-04-12 7:20:50 PM";
NSDate *date = [dateFormatter dateFromString:dateString];
NSLog(@"Date is %@", date.description);

实际输出:

Date is 1985-04-12 1010:20:50 AM +0000

预期产量

Date is 1985-04-12 10:20:50 AM +0000

如果我将小时更改为24小时格式(HH):

If I change the hour to 24 hour format (HH):

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss a";
NSString *dateString = @"1985-04-12 7:20:50 PM";
NSDate *date = [dateFormatter dateFromString:dateString];
NSLog(@"Date is %@", date.description);

实际输出:

Date is (null)

预期输出:

Date is 1985-04-12 10:20:50 AM +0000

推荐答案

我们也面临iOS 10.x的类似问题,并使用

We were also facing similar issue for iOS 10.x and fixed it using

NSLocale * POSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];dateFormatter.locale应该等于(POSIXLocale);

NSLocale *POSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; dateFormatter.locale should equal(POSIXLocale);

这篇关于iOS 10错误?日本地区的NSDate小时描述和24小时休息时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆