Green Files

How to make the date() function format a date in another language?

Day: 06/01/2022 - Time: 11:56:21

The original language of the date function date() is english, like for exemple Thursday 6th. Here's what to do to change the data's language:

Use strftime() to create the date in full, as this function automatically uses the locale. You'll just have to inform the locale

setlocale(LC_TIME, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese'); date_default_timezone_set('America/Sao_Paulo'); echo strftime('%A, %d de %B de %Y', strtotime('today'));


quinta-feira, 06 de março de 2014

%A: day of the week in full.

%d: day of the month represented with two digits.

%B: month in full.

%Y: year represented with four digits.

Approach with IntlDateFormatter

It is also possible to obtain the same result with the DateTime and IntlDateFormatter classes. It is important that the INTL library must be enabled.

The date and time formats are:

Data Constante |Saida FULL |segunda-feira, 1 de setembro de 2014 TRADITIONAL|segunda-feira, 1 de setembro de 2014 LONG |1 de setembro de 2014 MEDIUM |01/09/2014 SHORT |01/09/14 NONE | Hora Constante |Saida FULL |03h00min00s GMT+00:00 TRADITIONAL|03h00min00s GMT+00:00 LONG |03h00min00s GMT+00:00 MEDIUM |03:00:00 SHORT |03:00 NONE |

In the constructor it is necessary to inform four arguments: locale, date format, time format, timezone and the calendar type


For a custom output use the setPattern() method and specify the format as per the documentation