如何检查当前日期/时间是否超过设定的日期/时间? [英] How can I check if the current date/time is past a set date/time?

查看:148
本文介绍了如何检查当前日期/时间是否超过设定的日期/时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个脚本,以检查当前日期/时间是否超过了下午4点的 05/15/2010

I'm trying to write a script that will check if the current date/time is past the 05/15/2010 at 4PM

如何使用PHP的date()函数执行此检查?

How can I use PHP's date() function to perform this check?

推荐答案

由于PHP> = 5.2.0,您可以使用 DateTime 类:

Since PHP >= 5.2.0 you can use the DateTime class as such:

if (new DateTime() > new DateTime("2010-05-15 16:00:00")) {
    # current time is greater than 2010-05-15 16:00:00 and thus in the past
}

传递给 DateTime构造函数已被解析为根据这些规则

请注意,也可以使用 time code> strtotime 函数。 请参阅原始答案

Note that it is also possible to use time and strtotime functions. See original answer.

这篇关于如何检查当前日期/时间是否超过设定的日期/时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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