如何查找特定周的特定日期

时间:2015-12-22 21:56:06

标签: php date

我在Google上搜索并搜索了答案。我要么在寻找错误的东西,要么就是我要求做的事情(我希望能做到)

我需要在特定周中找到特定日日期。例如,我想知道星期二的第34周,或星期五的第2周的日期是什么。

我的PHP技能是介绍性的,我试图拼凑和操纵使用我已有的东西,但没有任何效果。

2 个答案:

答案 0 :(得分:1)

您可以使用复合格式

echo date( 'Y-m-d', strtotime( '2015W342' )); // 2015-08-18

其中值为:

  

2015 -Year

     

W34 - 周号

     

2 - 星期几

答案 1 :(得分:0)

也许你可以像

一样使用strtotime
print date('Y-m-d',strtotime('next Monday',strtotime('2016-01-01 +34 week')));
print date('Y-m-d',strtotime('last Monday',strtotime('2016-01-01 +34 week')));

#check if one of the dates is correct
var_export(date('W',strtotime('2016-10-10'))==34);

查看该主题的文档