Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么我使用“时间差”时会出现这种时间差;IntlDateFormatter";?_Php_Datetime_Datetime Format - Fatal编程技术网

Php 为什么我使用“时间差”时会出现这种时间差;IntlDateFormatter";?

Php 为什么我使用“时间差”时会出现这种时间差;IntlDateFormatter";?,php,datetime,datetime-format,Php,Datetime,Datetime Format,为什么在使用“IntlDateFormatter”时会出现这种时差 我认为intlDateFormatter和DateTime在1890年之前是不兼容的。 1890年后,欧洲逐步引进了中世纪时间(MET)。 1890年初,根据经度的不同,每个地方都有自己的时间。 下面的代码通过4个示例展示了这一点 $refDate = date_create('1890-01-01 UTC'); $ts = $refDate->getTimeStamp(); $pattern = 'yyyy-MM-dd

为什么在使用“IntlDateFormatter”时会出现这种时差


我认为intlDateFormatter和DateTime在1890年之前是不兼容的。
1890年后,欧洲逐步引进了中世纪时间(MET)。
1890年初,根据经度的不同,每个地方都有自己的时间。
下面的代码通过4个示例展示了这一点

$refDate = date_create('1890-01-01 UTC');
$ts = $refDate->getTimeStamp();
$pattern = 'yyyy-MM-dd HH:mm:ss';
$timezones = [
  "Europe/Paris",  //2.3522° E
  "Europe/Berlin", //13.4050° E
  "Europe/Prague", //14.4378° E
  "Europe/Budapest"//19.0402° E
];
$locale = 'hu_HU';

foreach($timezones as $timezone){
  $intlDateFormatter = new \IntlDateFormatter(
    $locale,  
    \IntlDateFormatter::MEDIUM, 
    \IntlDateFormatter::SHORT, 
    \IntlTimeZone::createTimeZone($timezone), 
    \IntlDateFormatter::GREGORIAN, 
    $pattern
  );

  $outputDateTimeStr = $intlDateFormatter->format($ts);
  echo $timezone.": ".$outputDateTimeStr."<br>";
}

DateTime提供其他结果。

为什么?$php intl_test.php in:1890-09-30 23:43:40 out:1890-09-30 23:43:40 diff:0秒$php intl_test.php in:1890-09-30 23:43:38 out:1890-09-30 23:59:58 diff:980秒
$refDate = date_create('1890-01-01 UTC');
$ts = $refDate->getTimeStamp();
$pattern = 'yyyy-MM-dd HH:mm:ss';
$timezones = [
  "Europe/Paris",  //2.3522° E
  "Europe/Berlin", //13.4050° E
  "Europe/Prague", //14.4378° E
  "Europe/Budapest"//19.0402° E
];
$locale = 'hu_HU';

foreach($timezones as $timezone){
  $intlDateFormatter = new \IntlDateFormatter(
    $locale,  
    \IntlDateFormatter::MEDIUM, 
    \IntlDateFormatter::SHORT, 
    \IntlTimeZone::createTimeZone($timezone), 
    \IntlDateFormatter::GREGORIAN, 
    $pattern
  );

  $outputDateTimeStr = $intlDateFormatter->format($ts);
  echo $timezone.": ".$outputDateTimeStr."<br>";
}
Europe/Paris: 1890-01-01 00:09:21
Europe/Berlin: 1890-01-01 00:53:28
Europe/Prague: 1890-01-01 00:57:44
Europe/Budapest: 1890-01-01 01:16:20