strtotime([月] [年]的第[天])

时间:2013-04-29 21:39:07

标签: php date strtotime

<?php
  $endDate = date("Y-m-d", strtotime("fourth monday april ". date("Y", strtotime("2013-04-01"))));     
  echo $endDate
?>

如果正确答案是2013-04-22,为什么这会输出2013-04-29?

当您搜索的那一天恰好在一个月的第一天出现时,日期计数器(即&#34;第四个&#34;)总是会显示一个比它应该的更多。

示例:&#34; 2013年3月3日星期三&#34;输出2013-05-22应该是2013-05-15。

我猜测解决这个问题的快捷方法是查看月份的第一天是否与您寻找的当天相同,并减少日期计数器(&#34;第四个&#34;,&#34;第三个&#34;等)?

2 个答案:

答案 0 :(得分:3)

将措辞更改为:

fouth monday of april ". date("Y", strtotime("2013-04-01"))

关键是of

答案 1 :(得分:-1)

如果其他人也在nth天寻找答案,例如上个月的15天:

date("Y-m-d", strtotime(date("Y-m-d", strtotime("first day of previous month") ).' + 14 days') );