```
#pragma mark? 比較takeCarTime與systemTime
- (NSUInteger )getHour:(NSString *)takeCarTime systemTime:(NSString *)systemTime
{
//? 時(shí)區(qū)相差8個(gè)小時(shí) 加上這個(gè)時(shí)區(qū)即是北京時(shí)間
NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
NSInteger delta = [timeZone secondsFromGMT];
// 兩個(gè)時(shí)間戳轉(zhuǎn)換日期類
// [takeCarTime doubleValue]/1000 這里除以1000 我們后臺(tái)傳來的時(shí)間戳有問題
NSDate? *DRstartDate = [[NSDate alloc] initWithTimeIntervalSince1970:[takeCarTime doubleValue]/1000 + delta];
NSDate *DRendDate = [[NSDate alloc] initWithTimeIntervalSince1970:[systemTime doubleValue]/1000 + delta];
// 日歷對(duì)象 (方便比較兩個(gè)日期之間的差距)
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];
// 獲得某個(gè)時(shí)間的年月日時(shí)分秒
//? ? ? ? NSDateComponents *createDateCmps = [calendar components:unit fromDate:DRstartDate];
//? ? ? ? NSDateComponents *nowCmps = [calendar components:unit fromDate:DRendDate];
NSLog(@"剩余%ld天,%ld小時(shí)%ld分", cmps.day ,cmps.hour, cmps.minute);
NSLog(@"相差%ld小時(shí)",cmps.hour);
return cmps.hour;
}
```