Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- setlocale(LC_ALL,"es_ES@euro","es_ES","esp");
- function time_ago($time)
- {
- $periods = array("Segundo", "Minuto", "Hora", "Día", "Semana", "Mes", "AƱo", "Decada");
- $lengths = array("60", "60", "24", "7", "4.35", "12", "10");
- $now = time();
- $difference = $now - $time;
- $tense = "Hace";
- if($difference < 10){
- return "Hace instantes";
- } else if (($difference > 10)&&($difference < 60)){
- return "Hace menos de un minuto";
- } else if ($difference > 432000){//Equivalent to 5 days.
- return strftime(("El %A %d de %B del %Y"), $time);
- }
- for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
- $difference /= $lengths[$j];
- }
- $difference = round($difference);
- if ($difference != 1) {
- $periods[$j].= "s";
- }
- return "$tense $difference $periods[$j] ";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement