0

I am looking a pure javascript which calculates date for friendly view.

eg. 05-24-2012 3:10

--> 20 minutes ago

I have a php script and I'm looking javascript version.

<?php
$time = strtotime($_GET["d"]);
echo humanTiming($time);
function humanTiming($time)
{
 $time=time()-$time;
 $tokens=array(31536000=>'year',2592000=>'month',604800=>'week',86400=>'day',3600=>'hour',60=>'minute',1=>'second');
 foreach($tokens as $unit=>$text){if($time<$unit) continue;$numberOfUnits = floor($time / $unit);return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');}
}
?>
Bora Alp Arat
  • 2,185
  • 3
  • 16
  • 21

2 Answers2

1

well javascript implementation of what u have posted is available here
also this may also be useful for you

Neji
  • 6,591
  • 5
  • 43
  • 66