时间戳

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

-(NSString *)timeStamp:(NSString *)data
{
    //时间戳
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    // 时间戳转时间的方法
    NSString *str = [NSString stringWithFormat:@"%@",data];
    NSTimeInterval time=[str doubleValue];
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:time];
    //NSLog(@"1383523892  = %@",confromTimesp);
    NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
    //NSLog(@"confromTimespStr =  %@",confromTimespStr);
    NSString *timeString =[confromTimespStr substringWithRange:NSMakeRange(0,10)];
    return timeString;
}