gpt4 book ai didi

iphone - 今天的 NSTimeInterval,时间为零(午夜)

转载 作者:行者123 更新时间:2023-11-29 10:59:31 26 4
gpt4 key购买 nike

我如何计算今天的 NSTimeInterval 时分秒为零?

我知道今天的NSTimeInterval是这样的:

NSTimeInterval  today = [[NSDate date] timeIntervalSince1970];

但是我该如何重置时间呢?

最佳答案

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];

关于iphone - 今天的 NSTimeInterval,时间为零(午夜),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16633837/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com