如何從根據區域設置格式化的NSString獲取NSDate(時間)?讓我解釋。基於設備的區域設置,我不得不myString的轉換成NSDate的在HH:SS(意大利格式)如何從NSString timeStyle獲取格式化爲區域設置的NSDate
NSLocale *locale = [NSLocale autoupdatingCurrentLocale];
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle: NSDateFormatterShortStyle];
[dateFormatter setDateStyle: NSDateFormatterFullStyle];
[dateFormatter setLocale: [[NSLocale alloc] initWithLocaleIdentifier: [locale objectForKey: NSLocaleIdentifier]]];
我的NSString可以是:@「2014年1月1日6:15 PM」或@ 「2014-01-01 18:15」或@「2014-01-01 6:15 MUU」或???? 我的結果必然是:@「2014年1月1日18:15」
[dateFormatter setDateFormat:@"????"];
NSDate *myDate = [dateFormatter dateFromString:myNSString];
我如何正確設置格式化的分區格式?
請搜索。有無數個將日期/時間字符串從一種格式轉換爲另一種格式的例子。 – rmaddy 2014-10-07 16:49:14
我嘗試了兩天,但找不到明確的解決方案。我做了很多次嘗試,但都沒有達到預期的效果 – Sgrappatore 2014-10-07 16:53:26
您需要兩個格式化程序。一個讀取原始字符串來創建'NSDate',另一個讀取'NSDate'到新的格式。 – rmaddy 2014-10-07 16:55:48