Approach with strftime
Use strftime () to create the date in full, as this function automatically picks up the locale. As quoted by @bfavaretto, just inform the locale.
strftime()
in the words of the manual:
Formats a local time / date according to the locale setting.
Name of the month and day of the week and other strings depend on the current location
defined with setlocale ().
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'));
output:
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.
Example - strftime
Approach with IntlDateFormatter
You can also get the same result with the DateTime and IntlDateFormatter . Important 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 |
Example - date / time format
In the constructor you need to enter four arguments: locale, date format, time format, timezone, and calendar type
<?php
date_default_timezone_set('America/Sao_Paulo');
$data = new DateTime();
$formatter = new IntlDateFormatter('pt_BR',
IntlDateFormatter::FULL,
IntlDateFormatter::NONE,
'America/Sao_Paulo',
IntlDateFormatter::GREGORIAN);
echo $formatter->format($data);
Example - IntlDateFormatter
For a custom output use the setPattern()
method and specify the format as per documentation
Relates to:
Use setlocale for date only