Skip to content

Instantly share code, notes, and snippets.

@whym
Created February 8, 2010 15:13
Show Gist options
  • Select an option

  • Save whym/298220 to your computer and use it in GitHub Desktop.

Select an option

Save whym/298220 to your computer and use it in GitHub Desktop.
var now = new Date();
var last_nyd = new Date(now.getFullYear(), 0, 1);
var next_nyd = new Date(now.getFullYear() + 1, 0, 1);
var rate = (now - last_nyd) / (next_nyd - last_nyd);
var beginning_of_today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
var one_day = 1000 * 60 * 60 * 24;
var pdate = new Date(beginning_of_today.getTime() + rate * one_day);
var hours = pdate.getHours();
var ampm = hours > 12 ? "PM" : "AM";
hours = hours > 12 ? hours - 12 : hours;
alert("You spent " + ((rate*1000|0) / 10) + "% of this year.\n" +
"If a year were a day, it would be " + hours +":"+ pdate.getMinutes() +":"+ pdate.getSeconds() +"."+ pdate.getMilliseconds() +" "+ ampm + " now.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment