iOS——json13位时间戳转换时间格式

/** 
 * Since1970
 */
+(NSString *)getNewDate:(NSString *)dateStr{

    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[dateStr doubleValue]/1000];

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

    //指定输出的格式  格式:07.06 12:33

    [formatter setDateFormat:@"MM.dd HH:mm"];

    NSString *timeString= [formatter stringFromDate:date];

    return timeString;

}

/** 
 * SinceNow
 */
+(NSString *)getYearsNumberDate:(NSString *)dateStr{/** sinceNow */

    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:[dateStr doubleValue]/1000];

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

    //指定输出的格式  格式:2016.07.06 12:33

    [formatter setDateFormat:@"yyyy.MM.dd HH:mm"];

    NSString *timeString= [formatter stringFromDate:date];

    return timeString;

}

你可能感兴趣的:(OC,Tool,ios,objective-c)