gpt4 book ai didi

ios-检查当前时间是否在两个时间之间

转载 作者:可可西里 更新时间:2023-11-01 05:01:01 25 4
gpt4 key购买 nike

我想检查当前时间是否在两个时间之间。

例如,我想检查当前时间是在今天上午 10 点到中午 12 点之间还是明天上午 10 点到中午 12 点之间。我该怎么做?

最佳答案

试试这个

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
NSInteger currentHour = [components hour];
NSInteger currentMinute = [components minute];
NSInteger currentSecond = [components second];

if (currentHour < 7 || (currentHour > 21 || currentHour == 21 && (currentMinute > 0 || currentSecond > 0))) {
// Do Something
}

用你的时间替换 7、21

我从 How to compare time 得到这个

关于ios-检查当前时间是否在两个时间之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13965921/

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