需求要在某個時段做某些事件,寫了個簡單的檢測函數。方便下次直接用。
/*
時間範圍
@st: start time,
@et: end time,
*/
function timeFrame(st, et){
st === undefined ? st = new Date().getTime() : st = Date.parse(st);
et = Date.parse(et);
//current time;
var ct = new Date().getTime();
if( ct > st && ct < et ){
return true;
}else{
return false;
}
}
console.log("現在是否 2016-12-29,16:30:00 至 2016-12-29,17:00:00 之間? is " +
timeFrame("2016-12-29,16:30:00", "2016-12-29,17:00:00"));