我已經用此代碼成功地將字符串中的日期進行了轉換。dateFromString在ios中正常工作
NSDateFormatter *df=[[NSDateFormatter alloc]init];
[df setDateFormat:@"dd/MM/yyyy HH:mm:ss"];
[df setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
NSString *strDate = [NSString stringWithFormat:@"%@", [unsortedArray objectAtIndex:i]];
NSDate *date =[df dateFromString:strDate];
這裏,unsortedArray
是日期數組。
我可以使用NSDateFormatter
作爲日期格式。
但在這裏,我無法獲得@"dd/MM/yyyy HH:mm:ss"
格式的日期。
我可以在這個格式得到日期:2013年3月8日9時07分16秒+0000
所以,我怎麼能在以下格式獲取日期:@"dd/MM/yyyy HH:mm:ss"
。
與往常一樣,你使用'NSLog'記錄日期,你得到'2013-03-08 09:07:16 + 0000',你認爲它的格式不正確,不是嗎? – Sulthan 2013-03-08 09:39:12