检查当前时间是否在其他时间之间 [英] Check if the current time is between other times

查看:82
本文介绍了检查当前时间是否在其他时间之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目上,该项目要求我的应用程序存储时间(类的起点和终点),并且每当打开应用程序时,它都需要检查当前时间是否在这些间隔中的任何一个之间,并执行一些操作因此.我在使用NSDateFromComponents时遇到的主要问题是,在指定的日期之后它不起作用.抱歉,这是一个显而易见的问题,但我是初学者.

I am working on a project that requires my application to store times (the start and end points of classes) and whenever the app is opened, it needs to check if the current time is between any of those intervals, and do something accordingly. The main problem I am having with NSDateFromComponents is that it does not work after the specified date. I apologize if this is an obvious question, but I am a beginner.

此致

HBhargava

HBhargava

推荐答案

如果您的时间是NSDate对象:

if ( ([currentTime compare:otherTime1] == NSOrderedDescending) &&
     ([currentTime compare:otherTime2] == NSOrderedAscending) ) {

}


另请参阅文档参考资料 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆