2 alllllllll alllllllll 于 2013.05.20 11:03 提问

NSTimeInterval时间零点

如何计算NSTimeInterval当日时间的时,分,秒为零点?

我只得到NSTimeInterval :

NSTimeInterval today = [[NSDate date] timeIntervalSince1970];

如何重置为00:00:00?

1个回答

garaster
garaster   2013.05.20 13:56
已采纳
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];
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!