两个时间差
2016-12-30 本文已影响2人
失忆的程序员
NSTimeInterval time1 = [@"1460428880" doubleValue];
NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:time1];
NSTimeInterval time2 = [@"1460448024" doubleValue];
NSDate *date2 = [NSDate dateWithTimeIntervalSince1970:time2];
NSLog(@"%@**************%@",date1,date2);
NSCalendar *cal = [NSCalendar currentCalendar];
unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *d = [cal components:unitFlags fromDate:date1 toDate:date2 options:0];
//总共有多少秒
long sec = [d hour]*3600+[d minute]*60+[d second];
NSLog(@"%ld小时 %ld分钟 %ld秒",[d hour],[d minute],[d second]);