我有一個iPhone應用程序。即正在接收具有IRFC 3339時間戳格式的數據(例如@「2010-01-29T11:30:00.000 + 01:00」),如在GData中。我想將數據轉換爲一個NSDate從NSString檢索NSDate
NSDateFormatter *inputFormatter = [[[NSDateFormatter alloc] init] autorelease];
[inputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
[currentEntry setStartTime:[inputFormatter dateFromString: ][currentEntry startTimeString]]];
但我錯過了如何將字符串的最後一部分轉換@「2010-01-29T11:30:00.000 + 01:00」:時間抵消。任何人都知道我必須添加到此字符串中以獲取時間偏移量嗎?
你的意思是我只需要添加一個Z到@「yyyy-MM-dd'T'HH:mm:ss.SSS」就像@「yyyy-MM-dd'T'HH:mm:ss.SSSZ」 ? – 2010-03-14 04:51:21
你是對的。 http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns 請注意GData,iirc,祖魯時間他們使用Z而不是-00:00,所以你可能不得不處理這個問題。 – 2010-03-14 04:52:28
是的,就是這樣。 – 2010-03-14 04:56:54