PHP检查当前时间是否在指定时间之前

编程入门 行业动态 更新时间:2024-10-28 13:26:10
本文介绍了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检查当前时间是否在指定时间之前

本文发布于:2023-11-24 09:54:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624742.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!