PHP strtotime() quot;first monday februaryquot; returns second monday if february 1st is a monday(PHP strtotime() “二月第一个星期一如果 2 月 1 日是星期一,则返回第二个星期一)
问题描述
我正在开发一个计算假期的 PHP 函数:
I'm working on a PHP function which calculates holidays:
function holidays($country = 1, $timespan_start = 0, $timespan_end = 0)
假期以数组中的时间戳形式返回.
The holidays are returned as timestamps in an array.
因为我必须计算像二月的第一个星期一这样的日期,所以我尝试了 strtotime("first monday february $year")
,我发现这对于 2010 年不起作用,因为 02/01/2010 是星期一 - 我改为 2 月 8 日.
Since I have to calculate dates like the first Monday of February, I tried strtotime("first monday february $year")
and I've discovered that this does not work for 2010, since 02/01/2010 is a Monday - I get February 8th instead.
这个bug其实是在变更日志中提到的:在 5.2.7 之前的 PHP 5 中,如果该工作日是该月的第一天,则请求在一个月内出现给定的工作日会错误地将一周添加到返回的时间戳.这已在 5.2.7 及更高版本中得到纠正.
This bug is actually mentioned in the change log: 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.3.8.为什么我会遇到此错误?
But I'm using PHP 5.3.8. Why am I experiencing this error?
推荐答案
看起来你只是少了一个of":
Looks like you are just missing an "of":
echo date('Y-m-d', strtotime('first monday of february 2010'));
将给出预期结果.有关各种输入格式,请参阅 PHP 相对日期手册.
will give the expected result. See the PHP Manual on Relative dates for the various input formats.
这篇关于PHP strtotime() “二月第一个星期一"如果 2 月 1 日是星期一,则返回第二个星期一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP strtotime() “二月第一个星期一"如果 2 月 1 日是星期一,则返回第二个星期一


- Mod使用GET变量将子域重写为PHP 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- Laravel 仓库 2022-01-01