【问题标题】:PHP check if a time is larger then or smaller then a specfic timePHP检查时间是否大于或小于特定时间
【发布时间】:2015-10-21 11:53:13
【问题描述】:

我知道可能有人问过这个问题, 但是我在任何地方都没有找到答案。

我想用 php.ini 确定当前时间是在上午 10:30 之前还是之后。我发现了很长的路要走,这需要大量的时间解析。但我相信有更好的方法。

this 的回答中,如果小时是整数(例如 2PM),它会显示如何操作

if( 'now' is larger then 'a given time' ){

}

【问题讨论】:

标签: php


【解决方案1】:

使用time()date()strtotime()函数:

if(time() > strtotime(date('Y-m-d').' 10:30') {
    //...
}

【讨论】:

    【解决方案2】:

    使用strtotime()。但请记住它接受日期对象。

    if(strtotime(dateobject) > strtotime(dateobject)){
      //
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-13
      • 2014-08-26
      相关资源
      最近更新 更多