时间转换

传入YYYYMMddHHmmss转成YYYY-MM-dd HH:mm:ss

+(NSString *)changTime:(NSString*)time{

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateStyle:NSDateFormatterMediumStyle];

[formatter setTimeStyle:NSDateFormatterShortStyle];

[formatter setDateFormat:@"YYYYMMddHHmmss"];

NSDate* date = [formatter dateFromString:time];

[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];

NSString *returnTime = [formatter stringFromDate:date];

return returnTime;

}

传入YYYYMMddHHmmss转成YYYY-MM-dd

+(NSString *)changTimeYYYYMMDD:(NSString*)time{

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateStyle:NSDateFormatterMediumStyle];

[formatter setTimeStyle:NSDateFormatterShortStyle];

[formatter setDateFormat:@"YYYYMMddHHmmss"];

NSDate* date = [formatter dateFromString:time];

[formatter setDateFormat:@"YYYY-MM-dd"];

NSString *returnTime = [formatter stringFromDate:date];

return returnTime;

}

传入YYYYMMddHHmmss转成yyyy年MM月dd日

+(NSString *)changeTime:(NSString*)time{

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateStyle:NSDateFormatterMediumStyle];

[formatter setTimeStyle:NSDateFormatterShortStyle];

[formatter setDateFormat:@"YYYYMMddHHmmss"];

NSDate* date = [formatter dateFromString:time];

[formatter setDateFormat:@"yyyy年MM月dd日"];

NSString *returnTime = [formatter stringFromDate:date];

return returnTime;

}

你可能感兴趣的:(时间转换)