Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2. setlocale(LC_ALL,"es_ES@euro","es_ES","esp");
  3.  
  4. function time_ago($time)
  5. {
  6. $periods = array("Segundo", "Minuto", "Hora", "D&iacute;a", "Semana", "Mes", "AƱo", "Decada");
  7. $lengths = array("60", "60", "24", "7", "4.35", "12", "10");
  8.  
  9. $now = time();
  10.  
  11. $difference     = $now - $time;
  12. $tense         = "Hace";
  13.  
  14. if($difference < 10){
  15.     return "Hace instantes";
  16. } else if (($difference > 10)&&($difference < 60)){
  17.     return "Hace menos de un minuto";
  18. } else if ($difference > 432000){//Equivalent to 5 days.
  19.     return strftime(("El %A %d de %B del %Y"), $time);
  20. }
  21.  
  22. for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
  23.     $difference /= $lengths[$j];
  24. }
  25.  
  26. $difference = round($difference);
  27.  
  28.  
  29.  
  30. if ($difference != 1) {
  31.     $periods[$j].= "s";
  32. }
  33.  
  34. return "$tense $difference $periods[$j] ";
  35. }
  36.  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement