Date in English (en-us) [duplicate]

4

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 it did not solve ...

    
asked by anonymous 11.02.2017 / 02:31

1 answer

5

Use %B for the month format and as method parameter date_default_timezone_set() use America/Sao_Paulo . Here is 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));

To stay logged in, I created a DataPorExtensoTimezonePTBR file in GitHub.

    
11.02.2017 / 03:04