PHP检查当前时间是否在指定时间之前 [英] PHP Check if current time is before specified time

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

问题描述

挣扎了一点,但肯定有一个简单的解决方案。基本上,如果当前时间是当天下午2点之前,我需要检查PHP。



我已经在日期之前使用了strtotime,但是这次是在一段时间只有这样,显然每天0.00,时间将重置,布尔值将从 false 重置为 true

  if(current_time< 2pm){

//这样做

}

任何帮助非常感谢!

解决方案

  if(date('H')< 14){
$ pre2pm = true;
}

这是一样容易,因为它匹配。



有关日期功能的更多信息,请查看PHP手册。我使用了以下时间格式化程序:


H =一小时的24小时格式(00到23)



Struggling a bit with this, but sure there's a simple solution. Basically I need to check in PHP if the current time is before 2pm that day.

I've done this with strtotime on dates before, however this time it's with a time only, so obviously at 0.00 each day the time will reset, and the boolean will reset from false to true.

if (current_time < 2pm) {

//do this

}

Any help much appreciated!

解决方案

if (date('H') < 14) {
   $pre2pm = true;
}

That is as easy as it gets mate.

For more information about the date function please see the PHP manual. I have used the following time formatter:

H = 24-hour format of an hour (00 to 23)

这篇关于PHP检查当前时间是否在指定时间之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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