mercredi 14 août 2019

Run JS between Friday 2 pm and Monday 7 am [on hold]

I want a script to execute only within friday 2pm and monday 7am. (I'm very new to JS, but the script needs to be in JS.)

I tried to set date and the current hour and day, but the if case seems not to be working that way. Alyways outputs true, even if conditions are not fullfilled..

var date = new Date();
var hour = date.getHours();
var day = date.getDay();


if (( day = 1 && hour <= 7 ) || ( day = 5 && hour >= 14 ) || ( day = 6 ) || ( day = 0 ))
{
    //do stuff
}

It should only run in specified time.

Aucun commentaire:

Enregistrer un commentaire