Skip to content

Instantly share code, notes, and snippets.

@trubachev
Last active December 25, 2015 00:08
Show Gist options
  • Save trubachev/6885054 to your computer and use it in GitHub Desktop.
Save trubachev/6885054 to your computer and use it in GitHub Desktop.
JavaScript function to return number of current day in year work well with leap-years
function getDayOfYear(){
var now = new Date();
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
return Math.floor(diff / oneDay);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment