PHP strtotime()"2月第一周一";如果2月1日是星期一,则返回第二个星期一 [英] PHP strtotime() "first monday february" returns second monday if february 1st is a monday

查看:164
本文介绍了PHP strtotime()"2月第一周一";如果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.

由于我必须像2月的第一个星期一那样计算日期,因此我尝试了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.

更改日志中实际上提到了此错误: 在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月第一周一";如果2月1日是星期一,则返回第二个星期一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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