ios-检查当前时间是否在两次之间 [英] ios- Check whether current time is between two times or not
本文介绍了ios-检查当前时间是否在两次之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查当前时间是否在两次之间。
I want to check whether the current time is between two time or not.
例如,我想检查当前时间是否在今天上午10点之间到12PM或明天早上10点到12点。我怎么能这样做?
For example, I want to check if the current time is between today morning 10AM to 12PM or Tomorrow morning 10AM to 12PM. How can I do this?
推荐答案
试试这个
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
Replace 7, 21 with your time
我从如何比较时间中得到这个
这篇关于ios-检查当前时间是否在两次之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文