Created
March 20, 2013 16:04
-
-
Save rkmaier/5205895 to your computer and use it in GitHub Desktop.
JS function for displaying tweet time
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 getTweetTime(timestamp) | |
{ | |
var time = (Date.parse(timestamp)/1000); | |
time = Math.round((((new Date()).getTime() / 1000)-time)/60); | |
if (time >= 60) { | |
var hours = Math.round(time / 60); | |
if (hours == 1) { | |
return "sent " + hours + " hour ago"; | |
} | |
if (hours >= 48) { | |
var days = Math.round(hours/24); | |
return "sent " + days + " days ago"; | |
} | |
return "sent " + hours + " hours ago"; | |
} | |
if (time < 60) { | |
if (time < 1) { | |
return "sent secs ago"; | |
} | |
if(time == 1) | |
{ | |
return "sent a minute ago"; | |
} | |
return "sent " + time + " mins ago"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment