我正在将 NSDate 对象转换为字符串格式。使用GHKit
. 在内部使用NSDateFormatter
stringFromDate
[NSDate date] gh_format:@"yyyy-MM-dd HH:mm:ss zzz" useWeekday:NO]
- (NSString *)gh_format:(NSString *)format useWeekday:(BOOL)useWeekday {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:format];
NSString *formatted = [dateFormatter stringFromDate:self];
if (useWeekday) {
NSString *specialWeekday = [self gh_weekday:dateFormatter];
formatted = [NSString stringWithFormat:@"%@, %@", specialWeekday, formatted];
}
[dateFormatter release];
return formatted;
}
此方法适用于 iOS 5、6,产生以下输出
2013-10-10 10:43:44 GMT+05:00
但是 iOS 7 会产生这样的东西,我的网络服务器无法解析
2013-10-10 10:43:44 GMT+5