gpt4 book ai didi

php - strtotime ('First Monday ..' ) 当它是一个月的第一天时返回错误的日期

转载 作者:行者123 更新时间:2023-12-01 22:40:29 27 4
gpt4 key购买 nike

 echo date('Y-m-d', strtotime('First Monday '.date('F o', strtotime("-4 months")));

以上代码返回 2012-10-08,这是不正确的 - 2012 年 10 月的第一个星期一应返回 2012-10-01。

手册中的变更日志 ( http://php.net/manual/en/function.strtotime.php ) 指定以下内容:

In PHP 5 prior to 5.2.7, requesting a given occurrence of a given weekday in a 
month where that weekday was the first day of the month would incorrectly add
one week to the returned timestamp.

This has been corrected in 5.2.7 and later versions.

很明显这是导致返回日期错误的原因,但我使用的是 PHP 5.4.7 版(在本地主机上运行 xamp)!

有什么想法吗?

最佳答案

在尝试检索月份的第一天时,您缺少关键字 of

echo date('Y-m-d', strtotime('First Monday of '.date('F o', strtotime("-4 months")));

我找到关于这个 bug report 的信息

我当前的版本是 PHP 5.4.4,以防它仍然不适合你

关于php - strtotime ('First Monday ..' ) 当它是一个月的第一天时返回错误的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14728833/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com