Skip to content

Instantly share code, notes, and snippets.

@Trott
Created March 18, 2014 18:36
Show Gist options
  • Save Trott/9626471 to your computer and use it in GitHub Desktop.
Save Trott/9626471 to your computer and use it in GitHub Desktop.
Timezone-independent countdown. Well, not a countdown, but you know, find out how long it is between now and the specified time.
// Get date object for the current time.
var now = new Date();
// Now let's get a timestamp for midnight UTC time.
// Well, one millisecond before midnight so we don't have to deal with incrementing.
var midnight = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 23, 59, 59, 999);
// And the number of minutes until that time.
var diffInMinutes = Math.round((midnight - now.getTime()) / (1000 * 60));
window.console.log("UTC midnight is " + diffInMinutes + " minutes away.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment