2009-10-21 42 views
0

以下代碼:NSDateFormatter返回1970,而不是當前年與格式MM/DD

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
[dateFormatter setDateFormat:@"MM/dd"]; 
NSDate *newTime = [dateFormatter dateFromString:@"10/01"]; 

設置生成的日期1970年10月1日到。是否有一個「正確」的方式有格式假設你的意思是在當前年份的日期,或最接近當前日期?

回答

0

你嘗試[dateFormatter setLenient:YES]

+0

完美,不知道我怎麼錯過了。謝謝。 – Hunter 2009-10-28 18:15:51

相關問題