目前我有一段代碼將一組用戶輸入的字符串(例如900130)轉換爲使用yyMMdd(馬來西亞IC)格式的日期。我的字符串轉換爲代碼如下:某日期的NSDate格式化不是有效日期
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyMMdd"];
date = [dateFormat dateFromString:temp]; // temp = string key in by user
當我運行一些測試並沒有出現我的問題,但是當我把它交給別人來測試它,會出現問題,在字符串490130應該將其轉換爲30/1/1949將其轉換爲30/1/2049。
如何轉換490130至30/1/1949,而不是30/1/2049
你想要兩位數的年份被認爲是19xx年還是20xx年? – rmaddy
添加100年到日期? – matt
或從日期減去100年。 – ozgur