我想检查一个给定的日期是第一个,第二个,第三个,第四个还是最后一个星期一,星期二,星期三,......,星期日是在日期月份.
该函数应如下所示:
if(checkdate(date, "second", "monday"))
{
alert("This is the second monday of the month");
}
else
{
alert("This is NOT the second monday of the month");
}
Run Code Online (Sandbox Code Playgroud)
我宁愿写一个函数返回一个对象,告诉我给定日期的日期和周数.就像是:
function infoDate(date) {
return {
day: date.getDay()+1,
week: (date.getDate()-1)%7+1
}
}
Run Code Online (Sandbox Code Playgroud)
然后我可以读取返回的对象并查明它是第二个星期一还是其他:
var info = infoDate(date);
if(info.day==1 && info.week==2) {
// second monday
}
Run Code Online (Sandbox Code Playgroud)
当然,您仍然可以根据数字和日期名称数组编写另一个完全符合您要求的本地化函数.