Developer/iOS

[iOS]NSDate 시간 차이 구하기

블로blow 2017. 5. 19. 15:07
728x90

NSDate *pastDate = ...;

NSDate *nowDate = [NSDate date]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSUInteger calendarUnit = NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;


NSDateComponents *dateComp = [calendar components: calendarUnit fromDate: nowDate toDate: pastDate options:0]; NSInteger day = dateComp.day; NSInteger hour = dateComp.hour; NSInteger min = dateComp.minute; NSInteger sec = dateComp.second;


728x90