问题描述
- NSTimeInterval时间零点
- 如何计算NSTimeInterval当日时间的时,分,秒为零点?
我只得到NSTimeInterval :
NSTimeInterval today = [[NSDate date] timeIntervalSince1970];
如何重置为00:00:00?
解决方案
NSDate *currentDate = [NSDate date];NSDateComponents *currentDateComponents = [calendar components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:currentDate];NSDateComponents *currentDateToMidnight = [[NSDateComponents alloc] init];[currentDateToMidnight setHour:-[currentDateComponents hour]];[currentDateToMidnight setMinute:-[currentDateComponents minute]];[currentDateToMidnight setSecond:-[currentDateComponents second]];NSDate *midnight = [calendar dateByAddingComponents:currentDateToMidnight toDate:currentDate options:0];NSTimeInterval todayTimeInterval = [midnight timeIntervalSince1970];
时间: 2024-11-02 01:42:22