Helo, 我正在嘗試一堆代碼,它給null。這段代碼有什麼問題嗎?NSDateFormatter @「mmddyyy」?
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// get NSDate from old string format
[dateFormatter setDateFormat:@"mmddyyy"];
NSDate *date = [dateFormatter dateFromString:@"02012002"];
NSLog(@"%@",date);
// get string in new date format
[dateFormatter setDateFormat:@"dd-MMM-yyyy"];
NSString *strMyDate= [dateFormatter stringFromDate:date];
NSLog(@"%@\n\n********************************************************",strMyDate);
輸出
2011-06-09 12:49:17.957 TestPrj[3054:207] (null)
2011-06-09 12:49:17.959 TestPrj[3054:207] (null)
********************************************************
thnaks點 – 2011-06-09 07:56:03