Guest User

Untitled

a guest
Jan 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. function calcPassedPercentageInThisYear(date) {
  2. var thisNewYear = new Date(date.getFullYear() + "/1/1");
  3. var nextNewYear = new Date((date.getFullYear()+1) + "/1/1");
  4. return 1 - (nextNewYear - date) / (nextNewYear - thisNewYear);
  5. }
  6.  
  7. var date = new Date();
  8. var passedPercentageInThisYear = Math.round(calcPassedPercentageInThisYear(date) * 10000.0) / 100.0;
  9. console.log(passedPercentageInThisYear + " percent has passed in this year!");
Add Comment
Please, Sign In to add comment