我之前的问题:how-to-find-current-day-no-in-month-in-php
现在我面临另一个问题。假设我知道此monday
是4th monday of the current month.
现在如何检查this monday is also the last monday of the current month
?
exa:1
date: 27-01-2014
使用下面的代码,我得到一天的名字和号码:
day: monday
day no :4th
这是1月的第4个星期一,也是1月的最后一个星期一。怎么检查?
exa:2
date: 20-01-2014
day: monday
day no :3rd
此处this monday is 3rd monday of january but not last monday of january.
所以,简而言之,当我得到一个天数时,如何检查天数是否是最后一天?
code:
$t=date('d-m-Y');
$dayName = strtolower(date("D",strtotime($t)));
$dayNum = strtolower(date("d",strtotime($t)));
$dayno = floor(($dayNum - 1) / 7) + 1
答案 0 :(得分:2)
只需将7天(您仍有星期一)添加到您拥有的日期,并检查它是否在同一个月内。
答案 1 :(得分:0)
完整的解决方案如下。感谢@Oliver M Grech和@Nanne。
$t=date('d-m-Y');
$day = strtolower(date("D",strtotime($t)));
$month = strtolower(date("m",strtotime($t)));
$dayNum = strtolower(date("d",strtotime($t)));
$weekno = floor(($dayNum - 1) / 7) + 1;
if($weekno=="4" or $weekno=="5")
{
$Date = date("d-m-Y");
$new_month = date('m', strtotime($Date. ' + 7 days'));
if($new_month != $month)
{
echo "This ".$day." is last day of month." ;
}
}
答案 2 :(得分:0)
最快的方式来检查今天是否是本月的最后一个我建议以下
const body = document.querySelector('body');