Advertisement
MxMCube

Untitled

Oct 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. function resetAtMidnight() {
  2. var now = new Date();
  3. var night = new Date(
  4. now.getFullYear(),
  5. now.getMonth(),
  6. now.getDate() + 1, // the next day, ...
  7. 0, 0, 0 // ...at 00:00:00 hours
  8. );
  9. var msToMidnight = night.getTime() - now.getTime();
  10.  
  11. setTimeout(function() {
  12. reset(); // <-- This is the function being called at midnight.
  13. resetAtMidnight(); // Then, reset again next midnight.
  14. }, msToMidnight);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement