时间和时间戳转化

、、、
NSDate *senddate = [NSDatedate];
NSLog(@"date1时间戳 = %ld",time(NULL));
NSString *date2 = [NSStringstringWithFormat:@"%ld", (long)[senddatetimeIntervalSince1970]];
NSLog(@"date2时间戳 = %@",date2);

    NSDateFormatter *dateformatter = [[NSDateFormatteralloc] init];
    [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSString *date1 = [dateformatter stringFromDate:senddate];
    NSLog(@"获取当前时间   = %@",date1);
    
    // 时间戳转时间
    NSDate *confromTimesp = [NSDatedateWithTimeIntervalSince1970:[senddate timeIntervalSince1970]];
    NSString *confromTimespStr = [dateformatterstringFromDate:confromTimesp];
    NSLog(@"时间戳转时间   = %@",confromTimespStr);

// 两个时间戳的间隔 返回的是秒
NSTimeInterval time = [now timeIntervalSinceDate:oldDate];
NSLog(@"time:%f",time/60/60/24);

、、、

你可能感兴趣的:(时间和时间戳转化)