下面的代码应该获取2月的第四个星期五和4月的第四个星期五,并返回它。
$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月1日是算数的。
任何想法,
太棒了
发布于 2011-03-30 21:41:28
您的代码无缘无故地非常复杂。试试这个(PHP 5.3):
$date = date('Y-m-d', strtotime('fourth friday of april 2011'));这将为您提供:
2011-04-22在PHP 5.2中,此语法似乎适用于所有情况:
$date = date('Y-m-d', strtotime('fourth friday', strtotime('april - 1 second')));发布于 2011-03-30 21:40:03
strtotime('fourth friday', $now)可能真正的意思是“相对于$now的第四个星期五”。
您提供的$now参数是2011年4月1日,这是一个星期五。4月1日之后的第四个星期五是这个月的第五个星期五。
发布于 2011-03-30 22:17:40
看起来您使用的是较旧版本的PHP。为了处理您在这里遇到的边缘情况,已经引入了主要的更改。在这种情况下,我认为以下是最干净的方法:
echo date('Y-m-d', strtotime('+4 fridays', mktime(0,0,0,4,0,date('Y'))));
// or
echo date('Y-m-d', strtotime('fourth friday', mktime(0,0,0,4,0,date('Y'))));这应该会给你今年4月的第四个星期五。我已经在5.3中测试成功了,但你必须在你的旧安装上进行测试。
https://stackoverflow.com/questions/5486949
复制相似问题