Skip to content

Instantly share code, notes, and snippets.

@NKid
Created April 17, 2013 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NKid/ce1f20677cdf52548c98 to your computer and use it in GitHub Desktop.
Save NKid/ce1f20677cdf52548c98 to your computer and use it in GitHub Desktop.
elapsedDays
function elapsedDays() {
var startDay = new Date('2010/08/28');
var now = new Date();
var today = new Date();
var totalDay, Y, M, D, strTime = '';
today.setFullYear(now.getFullYear(), now.getMonth(), now.getDate());
totalDay = parseInt((today - startDay) / 86400000, 10);
Y = Math.floor(totalDay / 365);
M = Math.floor((totalDay - Y * 365) / 30);
D = (totalDay - Y * 365 - M * 30);
if(Y > 0) strTime = Y + '年 ';
if(M > 0) strTime += M + '個月 ';
if(D > 0) strTime += D + '天';
return strTime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment