簡體   English   中英

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

[英]strtotime(nth [day] of [month] [year])

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

當正確答案是2013-04-22時,為什么會輸出2013-04-29?

每當您要搜索的日期恰好在一個月的第一天時,天數計數器(即“第四”)總是顯示多於應有的數。

示例:“ 2013年5月第3周三”輸出2013-05-22,應為2013-05-15。

我猜想解決此問題的快速方法將是查看該月的第一天是否與您要查找的同一天,並相應地減少天數計數器(“第四”,“第三”等)?

將措辭更改為:

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

關鍵之中of

如果其他人也在nth天(例如15日)在這里尋找答案,例如:

date("Ymd", strtotime(date("Ymd", strtotime("first day of previous month") ).' + 14 days') );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM