美文网首页
iOS 时间格式转换、时间戳排序

iOS 时间格式转换、时间戳排序

作者: 牛程程 | 来源:发表于2017-04-18 10:02 被阅读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、根据时间戳排序

    相关文章

      网友评论

          本文标题:iOS 时间格式转换、时间戳排序

          本文链接:https://www.haomeiwen.com/subject/dshfzttx.html