Yii2格式化程序asDate返回不同​​的日期

时间:2016-08-17 13:18:05

标签: php date yii2 formatter

我有2台服务器具有相同的项目代码,但我从生产服务器上的yii格式化程序获得不同的输出日,我不知道哪种配置可能导致这种差异......

它与此处讨论的主题Yii2 formater show different date不同,因为我认为它不是时区/小时差异,而是其输出始终前一天正确的日期。

在控制器中我从mysql列获取了一个日期时间的模型数据。 然后我记录不同的格式化字符串但总是获得相同的不同日期,前一天

\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));

我从生产服务器获得以下输出:

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 
)

测试服务器工作正常,它格式化日期时间...只有生产服务器有这个差异,yii配置相同

两台服务器之间的差异,但我不认为它可能导致问题,它是我获得timedatectl命令时的RTC时间:

在测试服务器中:

$ 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

在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

我也启用了Intl扩展,因为Yii Formatter文档说http://www.yiiframework.com/doc-2.0/guide-output-formatting.html#localizing-data-format

0 个答案:

没有答案