PHP是否自动将标准时间转换为日光节约时间


Does PHP automatically convert standard time to day light savings time?

PHP是否自动将标准时间转换为日光节约时间?例如,我们需要PST[$toTimezone]时区的时间,但PHP正在返回PDT。下面是我们正在使用的示例函数。

$fromTime = '2014-09-16 06:45:45';
$fromTimezone = 'GMT';
$toTimezone = 'PST';
function x($fromTime, $fromTimezone, $toTimezone,$format = 'l, F jS, Y g:i A T') {
  $fromTimezone = new 'DateTimeZone($fromTimezone);
  $toTimezone = new 'DateTimeZone($toTimezone);
  $orgTime = new 'DateTime($fromTime, $fromTimezone);
  $toTime = new 'DateTime($orgTime->format("c"));
  $toTime->setTimezone($toTimezone);
  return $toTime->format($format);
}

谨致问候,Vamsi Krishna Grandhi

PHP将把时间转换为当前观察到的时区。因此,就纽约而言,今天将在东部夏令时(-4),而在一年的最后一天,纽约将在东部标准时间。不遵守夏令时的亚利桑那州凤凰城一直处于山区标准时间。

$date = new DateTime('2014-09-16', new DateTimeZone('America/New_York'));
echo $date->format('c T');
$date = new DateTime('2014-09-16', new DateTimeZone('America/Phoenix'));
echo $date->format('c T');
$date = new DateTime('2014-12-31', new DateTimeZone('America/New_York'));
echo $date->format('c T');
$date = new DateTime('2014-12-31', new DateTimeZone('America/Phoenix'));
echo $date->format('c T');
2014-09-16T21:12:03-04:00 EDT
2014-09-16T18:12:03-07:00 MST
2014-12-31T00:00:00-05:00 EST
2014-12-31T00:00:00-07:00 MST