首页  >  文章  >  后端开发  >  如何在 PHP 中检查当前日期/时间是否已超过特定日期/时间?

如何在 PHP 中检查当前日期/时间是否已超过特定日期/时间?

DDD
DDD原创
2024-10-24 22:05:02945浏览

How to Check if the Current Date/Time Has Passed a Specific Date/Time in PHP?

检查当前日期/时间是否超过指定日期/时间

在 PHP 中,您可以轻松地使用 DateTime 类来确定当前日期/时间已超出特定日期/时间。

请考虑以下示例:

<code class="php">if (new DateTime() > new DateTime("2010-05-15 16:00:00")) {
    # The current time exceeds 2010-05-15 16:00:00.
    # In other words, it has passed.
}</code>

此代码使用 DateTime 构造函数,其中参数是遵守特定解析规则的字符串。通过比较当前日期/时间与指定日期/时间(05/15/2010 下午 4 点),您可以确定当前时间是否超过指定时刻。

以上是如何在 PHP 中检查当前日期/时间是否已超过特定日期/时间?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn