Skip to content

Instantly share code, notes, and snippets.

@grok
Created August 21, 2016 20:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grok/e57f9668928f534cfedb58d87003f8bd to your computer and use it in GitHub Desktop.
Save grok/e57f9668928f534cfedb58d87003f8bd to your computer and use it in GitHub Desktop.
This is the current hour of the year... but rolled back to the beginning of the day.
var timestmp = new Date().setFullYear(new Date().getFullYear(), 0, 1);
var yearFirstDay = Math.floor(timestmp / 86400000);
var today = Math.ceil((new Date().getTime()) / 86400000);
var dayOfYear = today - yearFirstDay;
var currentHourOfYear = dayOfYear * 24 - 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment