Skip to content

Instantly share code, notes, and snippets.

@rkmaier
Created March 20, 2013 16:04
Show Gist options
  • Save rkmaier/5205895 to your computer and use it in GitHub Desktop.
Save rkmaier/5205895 to your computer and use it in GitHub Desktop.
JS function for displaying tweet time
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