iOS 时间格式转换、时间戳排序
2017-04-18 本文已影响0人
牛程程
1、时间格式转换 NSString ~ NSDate、 NSString~NSDate
- (NSDate *)dateFromString:(NSString *)str
{
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMddHHmmss"];
[dateFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
return [dateFormat dateFromString:str];
}
- (NSString *)stringFromdate:(NSDate *)date
{
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
[dateFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
return [dateFormat stringFromDate:date];
}
2、根据时间戳排序