Created
July 21, 2022 13:22
-
-
Save dayaki/cb0346a6acb93f5b500dbec5b87d0fef to your computer and use it in GitHub Desktop.
Reset a variable daily
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myVar = 10; | |
function scheduleReset() { | |
// get current time | |
let reset = new Date(); | |
// update the Hours, mins, secs to the 24th hour (which is when the next day starts) | |
reset.setHours(24, 0, 0, 0); | |
// calc amount of time until restart | |
let t = reset.getTime() - Date.now(); | |
setTimeout(function() { | |
// reset variable | |
myVar = 1; | |
// schedule the next variable reset | |
scheduleReset(); | |
}, t); | |
} | |
scheduleReset(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment