//###############################
//Usage:
var myRelativeTime:String = timestampToRelative("Sun Oct 24 20:07:33 +0000 2010");
//returns a string
//###############################
function timestampToRelative(timestamp:String):String {
//--Parse the timestamp as a Date object--\\
var pastDate:Date = new Date(timestamp);
//--Get the current data in the same format--\\
var currentDate:Date = new Date();
//--seconds inbetween the current date and the past date--\\
var secondDiff:Number = (currentDate.getTime() - pastDate.getTime())/1000;
//--Return the relative equavalent time--\\
switch (true) {
case secondDiff < 60 :
return int(secondDiff) + ' seconds ago';
break;
case secondDiff < 120 :
return 'About a minute ago';
break;
case secondDiff < 3600 :
return int(secondDiff / 60) + ' minutes ago';
break;
case secondDiff < 7200 :
return 'About an hour ago';
break;
case secondDiff < 86400 :
return 'About ' + int(secondDiff / 3600) + ' hours ago';
break;
case secondDiff < 172800 :
return 'Yesterday';
break;
default :
return int(secondDiff / 86400) + ' days ago';
break;
}
}