1

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];
4

1 回答 1

1
 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);

可以帮助你。

于 2012-12-15T09:30:36.453 回答