Created
December 31, 2011 00:12
-
-
Save zpao/1542157 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function datediff(aDate1, aDate2) { | |
var diff = Math.abs(aDate2 - aDate1); | |
var milliseconds = diff % 1000; | |
var seconds = Math.floor(diff / 1000 % 60); | |
var minutes = Math.floor(diff / (1000 * 60) % 60); | |
var hours = Math.floor(diff / (1000 * 60 * 60) % 24); | |
var days = Math.floor(diff / (1000 * 60 * 60 * 24) % 365); | |
return [ | |
("00" + days).slice(-3), // DDD | |
("0" + hours).slice(-2), // HH | |
("0" + minutes).slice(-2), // MM | |
("0" + seconds).slice(-2), // SS | |
].join(":"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment