2
我有一個JSON格式,看起來像這樣的日期字符串:2014-02-07T00:00:00+08:00
JSON日期NSDate的結果爲零
而且我試圖把它與格式MM/dd/yyyy
轉換爲NSDate
。
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
NSDate *date = [dateFormat dateFromString:datestring];
NSDateFormatter *newDateFormatter = [[NSDateFormatter alloc]init];
[newDateFormatter setDateFormat:@"MM/dd/yyyy"];
NSString *newString = [newDateFormatter stringFromDate:date];
NSLog(@"Date: %@, formatted date: %@", date, newString);
但是結果是零。怎麼了?
請參閱此鏈接http://stackoverflow.com/questions/21522418/dateformatter-string-for- date-type-2013-03-24t021523-0800-objective-c/21522865#21522865 – RAJA