如何确定date是在javascript的周末
如果我有一个date进入一个函数,我怎么知道它是否是一个周末?
var day = yourDateObject.getDay(); var isWeekend = (day == 6) || (day == 0); // 6 = Saturday, 0 = Sunday
var isWeekend = yourDateObject.getDay()%6==0;
简短而甜蜜。
var isWeekend = ([0,6].indexOf(new Date().getDay()) != -1);
只需在modulo之前加1
var isWeekend = (yourDateObject.getDay() + 1) % 7 == 0;
var d = new Date(); var n = d.getDay(); if( n == 6 ) console.log("Its weekend!!"); else console.log("Its not weekend");