Skip to content

Instantly share code, notes, and snippets.

@u01jmg3
Created October 28, 2016 07:54
Show Gist options
  • Save u01jmg3/e20fe9acccd8becdb6ca67f45fe22afc to your computer and use it in GitHub Desktop.
Save u01jmg3/e20fe9acccd8becdb6ca67f45fe22afc to your computer and use it in GitHub Desktop.
Synchronise a timer to fire every new minute on a clock
var secondsRemaining;
let run_function = () => {
//
}
$(document).ready(function(){
run_function();
var time = new Date();
secondsRemaining = (60 - time.getSeconds()) * 1000;
setTimeout(function(){
run_function();
setInterval(function(){
run_function();
secondsRemaining = 0;
}, 60000); // 1 minute
}, secondsRemaining);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment