```
#pragma mark 比较takeCarTime与systemTime
- (NSUInteger )getHour:(NSString *)takeCarTime systemTime:(NSString *)systemTime
{
// 时区相差8个小时 加上这个时区即是北京时间
NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
NSInteger delta = [timeZone secondsFromGMT];
// 两个时间戳转换日期类
// [takeCarTime doubleValue]/1000 这里除以1000 我们后台传来的时间戳有问题
NSDate *DRstartDate = [[NSDate alloc] initWithTimeIntervalSince1970:[takeCarTime doubleValue]/1000 + delta];
NSDate *DRendDate = [[NSDate alloc] initWithTimeIntervalSince1970:[systemTime doubleValue]/1000 + delta];
// 日历对象 (方便比较两个日期之间的差距)
NSCalendar *calendar = [NSCalendar currentCalendar];
// NSCalendarUnit 枚举代表想获得哪些差值 NSCalendarUnitYear 年 NSCalendarUnitWeekOfMonth 月
NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitWeekOfMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
NSDateComponents *cmps = [calendar components:unit fromDate:DRendDate toDate:DRstartDate options:0];
// 获得某个时间的年月日时分秒
// NSDateComponents *createDateCmps = [calendar components:unit fromDate:DRstartDate];
// NSDateComponents *nowCmps = [calendar components:unit fromDate:DRendDate];
NSLog(@"剩余%ld天,%ld小时%ld分", cmps.day ,cmps.hour, cmps.minute);
NSLog(@"相差%ld小时",cmps.hour);
return cmps.hour;
}
```