转载地址:http://zani.iteye.com/blog/1144903
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate* dateFromString = [dateFormatter dateFromString:stringDate];
return dateFromString;
无论环境是使用12小时制还是24小时制,yyyy-MM-dd HH:mm:ss返回都是24小时制
设置TimeZone为UTC ,这样使得转换时间不会出现8小时误差
本文详细介绍了如何使用Objective-C中的NSDateFormatter类将日期字符串转换为24小时制,并设置时间为UTC时间,以避免因不同地区时区差异导致的时间转换误差。
2483

被折叠的 条评论
为什么被折叠?



