从NSString的格式化我有以下字符串表示日期&时间日期使用NSDateFormatter
NSString *shortDateString = @"Sat28Apr2012 15:00";
(没有空格(除了在前面的时候一个空格),就如同它是上面)
我想用格式化此日期:
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
// Question is regarding the line below:
[inputFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm"];
NSDate *formatterDate = [inputFormatter dateFromString:shortDateString];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[outputFormatter setTimeZone:gmt];
[outputFormatter setDateFormat:@"dd.MMM.yyyy HH:mm Z"];
NSString *newDateString = [outputFormatter stringFromDate:formatterDate];
您的字符串缺少有关年份的信息。 – dasblinkenlight 2012-02-05 11:27:04
是的,固定的那 – chewy 2012-02-05 11:31:19
那么年份和时间之间是否有空格,或者“没有空格,就像上面一样”评论仍然适用? – dasblinkenlight 2012-02-05 11:33:02