![](/img/trans.png)
[英]iPad App name & splashscreen is different on the simulator as the iPad device
[英]NSDate different in simulator and device(ipad)
嗨,我正在将我的项目中的GMT时间转换为本地时间-在所有模拟器和iPhone / iPod中都获得了正确的值-但是在iPad上运行时,我得到的是空值,这是我的代码-
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"HH:mm:ss";
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateFormatter setTimeZone:gmt];
NSDate *startDate = [dateFormatter dateFromString:@"14:37:00"];
NSLog(@"startDate---%@",startDate);
//This is startDate---2000-01-01 14:37:00 +0000 (in simulator/iPod/iphone)
// startDate---(null) (in ipad)
问题是用户的ipad的时间格式-如果是12小时格式-则以上代码结果为空我该怎么办?
因为您在ipad设备上将时间格式设置为12小时,所以日期字符串为24小时格式,请查看字符串@“ 14:37:00”。
采用
dateFormatter.dateFormat = @"hh:mm:ss";
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
如果要强制将其设置为12小时制,而无论用户的24/12小时制设置如何,都应将语言环境设置为en_US_POSIX。
使用hh代替HH。
hh通常是12小时,而HH通常是24小时。
由Apple自己链接的一个很好的官方参考书在这里 。 正如Zaph所提到的,另一个好的表在这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.