Created
April 7, 2012 05:35
-
-
Save clc510/2325564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertir($fecha) { | |
$months = array(); | |
$months [] = "Enero"; | |
$months [] = "Febrero"; | |
$months [] = "Marzo"; | |
$months [] = "Abril"; | |
$months [] = "Mayo"; | |
$months [] = "Junio"; | |
$months [] = "Julio"; | |
$months [] = "Agosto"; | |
$months [] = "Septiembre"; | |
$months [] = "Octubre"; | |
$months [] = "Noviembre"; | |
$months [] = "Diciembre"; | |
$diferencia = time() - $fecha; | |
$tiempo; | |
if($diferencia < 60) { | |
$tiempo = "Hace menos de 1 minuto."; | |
} | |
else { | |
if($diferencia < 60*60) { | |
$tiempo = "Hace ".(int) date("i", $diferencia); | |
if(date("i", $diferencia) == 1) { | |
$tiempo .= " minuto."; | |
} | |
else { | |
$tiempo .= " minutos."; | |
} | |
} | |
else { | |
if($diferencia < 60*60*24) { | |
$hour = date("H", time()) - date("H", $fecha); | |
if($hour < 0) | |
$hour *= (-1); | |
$tiempo = "Hace ".$hour; | |
if($hour > 0) { | |
if($hour == 1) { | |
$tiempo .= " hora."; | |
} | |
else { | |
$tiempo .= " horas."; | |
} | |
} else { | |
$tiempo = "Hace 23 horas"; | |
} | |
} | |
else { | |
$hora = (int) date("H", $fecha).":".date("i", $fecha); | |
$tiempo = $months[(int) date("m", $fecha) - 1]." ".(int) date("d", $fecha)." de ".date("Y", $fecha); | |
if(date("G", $fecha) < 13) { | |
$hora .= " am."; | |
} | |
else { | |
$hora .= " pm."; | |
} | |
if(date("H", $fecha) == 1) { | |
$tiempo .= " a la ". $hora; | |
} | |
else { | |
$tiempo .= " a las ". $hora; | |
} | |
} | |
} | |
} | |
return $tiempo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment