PHP Strtotime 不稳定函数 [英] PHP Strtotime erratic function
本文介绍了PHP Strtotime 不稳定函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码应该取二月的第四个星期五和四月的第四个星期五并返回.
The following code should take the fourth friday of February and the fourth friday of April and return it.
$datei1 = date(strtotime('fourth friday', strtotime('february', strtotime(date('01-m-Y')))));
$datei2 = date(strtotime('fourth friday', strtotime('april', strtotime(date('01-m-Y')))));
它可以工作,但在 4 月的第 5 个星期五而不是第 4 个星期五.我只能假设它不相信四月一日算数.
Its working but taking the 5th friday of April not the fourth. I can only assume that it does not believe the first of April counts.
任何想法,
太棒了
推荐答案
你的代码毫无缘由地非常复杂.试试这个(PHP 5.3):
Your code is very complicated for no reason. Try this (PHP 5.3):
$date = date('Y-m-d', strtotime('fourth friday of april 2011'));
这会给你:
2011-04-22
在 PHP 5.2 中,此语法似乎适用于所有情况:
In PHP 5.2, this syntax seems to work in all cases:
$date = date('Y-m-d', strtotime('fourth friday', strtotime('april - 1 second')));
这篇关于PHP Strtotime 不稳定函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文