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、根据时间戳排序

网友评论