iOS时间戳

来源:互联网 发布:52mac网可靠吗 编辑:程序博客网 时间:2024/05/18 13:10
        NSTimeInterval interval = [[NSDate date] timeIntervalSince1970] * 1000;         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);

原创粉丝点击