Created
June 9, 2009 11:48
-
-
Save zmack/126434 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 relative_time(C) { | |
var A = Date.parse(C); | |
var D = (arguments.length > 1) ? arguments[1] : new Date; | |
var E = parseInt((D.getTime() - A) / 1000); | |
//E = E + D.getTimezoneOffset() * 60; | |
if (E < 60) { | |
return "less than a minute ago"; | |
} else { | |
if (E < 120) { | |
return "about a minute ago"; | |
} else { | |
if (E < 3600) { | |
return parseInt(E / 60).toString() + " minutes ago"; | |
} else { | |
if (E < 7200) { | |
return "about an hour ago"; | |
} else { | |
if (E < 86400) { | |
return "about " + parseInt(E / 3600).toString() + " hours ago"; | |
} else { | |
if (E < 172800) { | |
return "1 day ago"; | |
} else { | |
return parseInt(E / 86400).toString() + " days ago"; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
(function() { | |
var z = document.getElementById('gufi'); | |
z.innerHTML = relative_time(z.innerHTML); | |
})(); |
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
<html> | |
<head> | |
<title>Test</title> | |
</head> | |
<body> | |
<span id="gufi">Tue Jun 09 2009 15:10:37 GMT+0300</span> | |
<script type="text/javascript" src="gistfile1.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment