NSDateFormatter提供的默認日期:
2001-01-01 00:00:00 +0000
我要輸出這樣的格式: January, 01 2013 04:00:00
代碼如下:
NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMMM, dd yyyy HH:mm:ss"];
NSDate *startDt=[_calendarDetailsDict objectForKey:@"dtStart"];
NSDate *endDt=[_calendarDetailsDict objectForKey:@"dtEnd"];
NSString *str=[formatter stringFromDate:startDt];
NSString *str1=[formatter stringFromDate:endDt];
NSString *dateStr =@"2012-09-15 00:11:59";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *date = [dateFormat dateFromString:dateStr];
dateFormat setDateFormat:@"MMMM, dd yyyy HH:mm:ss"];
NSString *dateString = [dateFormat stringFromDate:date];
NSLog(@"date: %@", dateString);
這樣就行了。