Php Yii2格式化程序asDate返回不同日期
我有两台具有相同项目代码的服务器,但我从生产服务器上的yii格式化程序获得的输出日期不同,我不知道是什么配置导致了这种差异 它与这里讨论的主题不同,因为我认为它不是时区/小时差,而是它的输出总是在正确日期的前一天 在controller中,我从mysql列中获取了一个模型数据,该列是datetime。 然后我记录不同的格式化程序字符串,但总是在1天前记录相同的不同日期 我从生产服务器获得以下输出:Php Yii2格式化程序asDate返回不同日期,php,date,yii2,formatter,Php,Date,Yii2,Formatter,我有两台具有相同项目代码的服务器,但我从生产服务器上的yii格式化程序获得的输出日期不同,我不知道是什么配置导致了这种差异 它与这里讨论的主题不同,因为我认为它不是时区/小时差,而是它的输出总是在正确日期的前一天 在controller中,我从mysql列中获取了一个模型数据,该列是datetime。 然后我记录不同的格式化程序字符串,但总是在1天前记录相同的不同日期 我从生产服务器获得以下输出: fechaEntrega in BD: 2016-08-23 00:00:00 fechaEntr
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
)
在生产服务器中:
# 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格式化程序文档中说明了当
$model->fechaEntrega
距离2016-08-23 00:00:00
超过3小时时,两台服务器上会发生什么情况?例如2016-08-23 04:00
?我只使用日期部分,时间设置为00:00:00y打印检查时间和Bizley您在正确的轨道上!fechaEntrega formatter as date:php:d-m-Y H:i:s:22-08-2016 23:00:00将其转换为1小时之前,因此它更改了日期。。。。这可能是一个时区问题,因为在智利,我们有GMT-4和GMT-3,有些地方一定会出错,但在哪里,服务器和RTC之间存在差异。尝试在整个应用程序的配置中设置'timeZone'=>'America/Santiago'
(在主级别,而不仅仅是在格式化程序组件中),并让我知道这是否有任何作用。我已经在应用程序配置中将时区设置为'America/Santiago'。使用格式化程序时的差异是提前1小时。。。似乎在某个地方把“美国/圣地亚哥”改为GMT-4而不是GMT-3??
$ 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
# 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