我正在使用以下代码将 an 转换NSString
为NSDate
:
+(NSDate *)dateOfDateTimeString:(NSString *)string {
NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy.MM.dd_HH:mm aa"];
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSDate *date = [dateFormatter dateFromString:string];
NSLog(@"try to convert string: %@ to date: %@", string, date);
return date;
}
但是我得到了意想不到的结果:
2012-06-14 22:26:59.208 Motilink[2223:707] +[NSDate(Util) dateOfDateTimeString:][Line 117] 尝试转换字符串:
2012.06.12_21:26 PM 至今:2012-06-12 03:26:00 +0000
2012-06-14 22:26:59.226 Motilink[2223:707] +[NSDate(Util) dateOfDateTimeString:][Line 117] 尝试转换字符串:
2012.06.13_15:00 PM 至今:2012-06-13 03:00:00 +0000
我究竟做错了什么?