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 日是星期一,则返回第二个星期一


基础教程推荐
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01