Skip to content

Instantly share code, notes, and snippets.

@MJ111
Created July 20, 2017 06:25
Show Gist options
  • Save MJ111/d30a5934361662dae36fd7a650126233 to your computer and use it in GitHub Desktop.
Save MJ111/d30a5934361662dae36fd7a650126233 to your computer and use it in GitHub Desktop.
Calculate milliseconds between midnight and present time according to universal time
const now = new Date();
const utcnow = Date.UTC(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate(),
now.getUTCHours(),
now.getUTCMinutes(),
now.getUTCMilliseconds()
);
let utctmr = Date.UTC(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate() + 1,
0,
0,
0
);
setTimeout(() => {
console.log('gotcha!')
}, utctmr - utcnow);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment