I have 2 servers with the same project code but i get different output day from the yii formatter on the production server and i have no clue what configuration could cause this difference...
it's different from the topic discussed here Yii2 formater show different date because i think its not a timezone/hour difference, instead its outputs always 1 day before the correct date.
in controller i have get a model data from mysql column that is a datetime. then i log different formatter strings but always same different date obtained, 1 day before.
\Yii::trace('fechaEntrega in BD: '.$model->fechaEntrega);
$fmt = 'php:d-m-Y';
\Yii::trace('fechaEntrega formatter as date: '.$fmt.': '.\Yii::$app->formatter->asDate($model->fechaEntrega, $fmt));
$fmt = 'd-M-Y';
\Yii::trace('fechaEntrega formatter as date: '.$fmt.': '.\Yii::$app->formatter->asDate($model->fechaEntrega, $fmt));
$fmt = 'php:Y-m-d';
\Yii::trace('fechaEntrega formatter as date: '.$fmt.': '.\Yii::$app->formatter->asDate($model->fechaEntrega, $fmt));
$formatter = \Yii::$app->formatter;
\Yii::trace('Formatter config: '.\yii\helpers\VarDumper::dumpAsString(\Yii::$app->formatter));
I get the follow output from production server:
fechaEntrega in BD: 2016-08-23 00:00:00
fechaEntrega formatter as date: php:d-m-Y: 22-08-2016
fechaEntrega formatter as date: d-M-Y: 22-8-2016
fechaEntrega formatter as date: php:Y-m-d: 2016-08-22
Formatter config: yii\i18n\Formatter#1 (
[nullDisplay] => '<span class=\"not-set\">(no definido)</span>'
[booleanFormat] => [ 0 => 'No' 1 => 'Sí' ]
[locale] => 'es-CL'
[timeZone] => 'America/Santiago'
[defaultTimeZone] => 'America/Santiago'
[dateFormat] => 'php:d-m-Y'
[timeFormat] => 'medium'
[datetimeFormat] => 'medium'
[calendar] => null
[decimalSeparator] => null
[thousandSeparator] => null
[numberFormatterOptions] => []
[numberFormatterTextOptions] => []
[numberFormatterSymbols] => []
[currencyCode] => null
[sizeFormatBase] => 1024
[yii\i18n\Formatter:_intlLoaded] => true
[yii\i18n\Formatter:_dateFormats] => [ 'short' => 3 'medium' => 2 'long' => 1 'full' => 0 ]
[yii\base\Component:_events] => []
[yii\base\Component:_behaviors] => null
)
The test server works fine, it formats right the datetimes... only production server have this difference and yii config its the same
the one differencebetween the 2 servers, but i dont think it could cause the issue, its the RTC time when i get the timedatectl command:
in Test server:
$ timedatectl
Local time: mié 2016-08-17 10:03:29 CLST
Universal time: mié 2016-08-17 13:03:29 UTC
RTC time: mié 2016-08-17 09:04:02
Time zone: America/Santiago (CLST, -0300)
Network time on: yes
NTP synchronized: no
RTC in local TZ: yes
$ date
mié ago 17 10:07:29 CLST 2016
And in Production Server:
# timedatectl
Local time: Wed 2016-08-17 10:03:16 CLST
Universal time: Wed 2016-08-17 13:03:16 UTC
RTC time: Wed 2016-08-17 13:03:16
Timezone: America/Santiago (CLST, -0300)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: yes
Last DST change: DST began at
Sat 2016-08-13 23:59:59 CLT
Sun 2016-08-14 01:00:00 CLST
Next DST change: DST ends (the clock jumps one hour backwards) at
Sat 2017-05-13 23:59:59 CLST
Sat 2017-05-13 23:00:00 CLT
# date
Wed Aug 17 10:07:18 CLST 2016
Also i have the Intl extension enabled as the Yii Formatter documentation says http://www.yiiframework.com/doc-2.0/guide-output-formatting.html#localizing-data-format