时间字符串的处理
这个是从网上找的例子,自己记录下来
NSString* string = @"20110826134106";
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] ];
[inputFormatter setDateFormat:@"yyyyMMddHHmmss"];
NSDate* inputDate = [inputFormatter dateFromString:string];
NSLog(@"date = %@", inputDate);
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setLocale:[NSLocale currentLocale]];
// [outputFormatter setDateFormat:@"yyyy年MM月dd日 HH时mm分ss秒"];
[outputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *str = [outputFormatter stringFromDate:inputDate];
NSLog(@"testDate:%@", str);
- 输出结果如下
2016-07-02 12:39:29.064 CMCCMall[20437:7141275] date = 2011-08-26 05:41:06 +0000
2016-07-02 12:39:29.065 CMCCMall[20437:7141275] testDate:2011-08-26 13:41:06