![](/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.