Skip to content

Instantly share code, notes, and snippets.

@dayaki
Created July 21, 2022 13:22
Show Gist options
  • Select an option

  • Save dayaki/cb0346a6acb93f5b500dbec5b87d0fef to your computer and use it in GitHub Desktop.

Select an option

Save dayaki/cb0346a6acb93f5b500dbec5b87d0fef to your computer and use it in GitHub Desktop.

Revisions

  1. dayaki created this gist Jul 21, 2022.
    18 changes: 18 additions & 0 deletions reset.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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();