问题描述
- 转化NSDate的NSDateFormatter问题
-
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);
这样就行了。
解决方案二:
真的受用了,谢了啊;
时间: 2024-09-26 16:14:58