Date in Portuguese (en-br)

Asked

Viewed 3,033 times

6

I have the following code in PHP:

<?php 
setlocale(LC_ALL, "pt_BR", "pt_BR.iso-8859-1", "pt_BR.utf-8", "portuguese");
$tz_object = new DateTimeZone('Brazil/East');

$datetime = new DateTime();
$datetime->setTimezone($tz_object);

$dia = $datetime->format('d'); 
$mes = $datetime->format('F');
$ano = $datetime->format('Y');

echo $dia . " de " . $mes . " de " . $ano;
?>

but the date comes in English:

10 de February de 2017

How can I adjust this ? I put a setlocale at the beginning of the code but did not resolve...

  • Check this solution: http://answall.com/questions/8317/como-fazer-a-fun%C3%A7%C3%A3o-date-formatar-uma-data-em-portugu%C3%Aas

1 answer

9


Use the %B for the month format and as a method parameter date_default_timezone_set() use America/Sao_Paulo. See a simple example:

setlocale(LC_TIME, 'portuguese'); 
date_default_timezone_set('America/Sao_Paulo');

$date = date('Y-m-d');
echo strftime("%d de %B de %Y", strtotime($date));

For the record, I created a file Dataporextensotimezoneptbr on Github.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.