Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var begin = "2002 May 1 22:15:43";
- var end = "2012 May 1 22:15:43";
- date1.setTime(Date.parse(begin));
- date2.setTime(Date.parse(end));
- var interval = date2 - date1;
- var seconds = interval / 1000;
- var secondsInOneDay = 86400;
- var years = Math.floor(seconds / secondsInOneDay / 365);
- seconds %= secondsInOneDay * 365;
- var months = Math.floor(seconds / secondsInOneDay / 30);
- seconds %= secondsInOneDay * 30;
- var days = Math.floor(seconds / secondsInOneDay);
- seconds %= secondsInOneDay;
- var hours = Math.floor(seconds / 3600);
- seconds %= 3600;
- var minutes = Math.floor(seconds / 60);
- seconds %= 60;
- console.log("years: " + years + ", months: " + months + ", days: " + days + ", hours: " + hours
- + ", minutes: " + minutes + ", seconds: " + seconds);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement