Created
September 11, 2013 19:39
-
-
Save realguess/6528734 to your computer and use it in GitHub Desktop.
Get the number of days since the beginning of the year.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Days Passed Since New Year | |
// ========================== | |
// | |
// (c) 2013 Chao Huang <chao@realguess.net> | |
// Quick Example | |
// ------------- | |
function days() { | |
return (new Date(new Date().toISOString().substr(0,10)).getTime() - new Date('' + new Date().getFullYear()).getTime()) / (1000 * (60 * 60 * 24)); | |
} | |
console.log(days()); | |
// Detail Explanation | |
// ------------------ | |
(function () { | |
var seconds = 60 * 60 * 24; // seconds in a day | |
var day1 = new Date('' + new Date().getFullYear()); | |
var today = new Date(new Date().toISOString().substr(0,10)); | |
console.log((today.getTime() - day1.getTime()) / (1000 * seconds)); | |
}).call(this); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment