我要查找本月 29 日、下个月 29 日、上个月 29 日等等的日期...
我知道您可以使用这种代码来查找星期几:
$friday_last = date("d/m/Y", strtotime("last Friday"));
$friday_due = date("d/m/Y", strtotime("this Friday"));
是否有类似的方法来查找每个月的某一天(29 日),或者我是否必须使用不同的代码?
最佳答案
您需要使用 DateTime()
,因为它 可以更轻松地处理日期。您会注意到我从每个月的第一天开始。这样一来,当您到达每个月的 29 日至 30 日时,奇怪的事情开始发生,这不会中断。
echo (new DateTime())->modify('first day of this month')->format("29/m/Y");
echo (new DateTime())->modify('first day of previous month')->format("29/m/Y");
echo (new DateTime())->modify('first day of next month')->format("29/m/Y");
echo (new DateTime())->modify('first day of this month')->modify('-2 months')->format("29/m/Y");
关于php - 查找上个月 29 日、两个月前等的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37004724/