Return to Snippet

Revision: 50731
at August 31, 2011 09:57 by Jotape


Initial Code
<?php

function format_date($unix, $format = '')
{
	if ($unix == '' || ! is_numeric($unix))
	{
		$unix = strtotime($unix);
	}

	if ( ! $format)
	{
		$format = 'd/m/Y H:i:s';
	}

	return strstr($format, '%') !== FALSE
		? ucfirst(strftime($format, $unix)) //or? strftime($format, $unix)
		: date($format, $unix);
}

$agora = time();
echo "Original: " . $agora . "<br />";

setlocale(LC_ALL, "pt_BR", "ptb");
echo "Formatada: " . format_date($agora, 'hoje é %d de %B de %Y'). "<br />";
echo "Formatada: " . format_date($agora). "<br />";
?>

Initial URL


Initial Description
Função para formatar datas em formato UNIX

Initial Title
Format date Local

Initial Tags
php

Initial Language
PHP