您的位置:首页 > 移动开发 > IOS开发

iOS 获取当前时间戳和时间

2016-02-18 17:20 387 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: