2014-04-01 45 views
-8

在這裏我得到日誌NSLog(@"dateString2 is%@%@",record.trigger_end_date,dateString2);dateString2 is2014-04-30T00:00:002014-04-30T00:00:00NSLog(@"date2 is%@",date2); is date2 is(null)轉換的NSString的NSDate給出零

+1

一個微不足道的問題。這在文檔中有明確的解釋。 –

+0

我有一種感覺,它之前也被問過...... – trojanfoe

+0

你試過Google嗎? –

回答

-2

我會關閉這個主題爲重複,但我不能決定選擇了其他主題(有這麼多的問題,要求相同),所以這裏是一個答案:

formatter2.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";

+0

請問這個答案是否會降低這個答案,請評論downvoting的原因? – tilo

0

我知道這個問題重複類別假我也標記了它。但我在這裏回答解釋,如果在OP沒有得到參考。

NSString *dateString = @"2014-04-30T00:00:00"; //input string 
NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; 
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];// fomatter in your case 
NSDate *date = [formatter dateFromString:dateString]; 
NSLog(@"date is%@",date); 

output - date is2014-04-29 18:30:00 +0000