检查我当前日期的哪一天,此解决方案是否也适用于该情况?就像今天11/21/2016是一个月的第三个星期一。
答案 0 :(得分:0)
尝试https://jsfiddle.net/z6zum0hk/
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var days = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
var weeksPassed = Math.floor(date.getDate()/7);
if(date.getDay() >= firstDay.getDay()){
alert((weeksPassed+1) + " " + days[date.getDay()] + " of month" )
}else{
alert((weeksPassed) + " "+ days[date.getDay()] + " of month" )
}
解释:
日期将为您提供月份日期,以便您可以找到已经过了多少个星期 每天将给你0至6天的太阳坐 所以,如果你当前的日子是在一天的开始月份之前,那么当天就过去了几天,其他几周过去了+ 1天