js获取某年某月的哪些天是周六和周日。最好能区分周六和周天。
发布网友
发布时间:2022-05-18 16:25
我来回答
共3个回答
热心网友
时间:2022-05-18 17:54
<p id="text"></p>
<script type="text/javascript">
function time(y,m){
var tempTime = new Date(y,m,0);
var time = new Date();
var saturday = new Array();
var sunday = new Array();
for(var i=1;i<=tempTime.getDate();i++){
time.setFullYear(y,m-1,i);
var day = time.getDay();
if(day == 6){
saturday.push(i);
}else if(day == 0){
sunday.push(i);
}
}
var text = y+"年"+m+"月份"+"<br />"
+"周六:"+saturday.toString()+"<br />"
+"周日:"+sunday.toString();
document.getElementById("text").innerHTML = text;
}
time(2014,7);
</script>
热心网友
时间:2022-05-18 19:12
function getWeekend(date) {
var week = { sat: [], sun: [] }, td, day, d;
for (var i = 1; i <= 31; i++) {
td = new Date(date + '/' + i);
day = td.getDay();
d = td.getDate();
if (!isNaN(day)) {
if (day == 0) {
week.sun.push(d);
} else if (day == 6) {
week.sat.push(d);
}
}
}
return week;
}