Php 为什么我使用“时间差”时会出现这种时间差;IntlDateFormatter";?
为什么在使用“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和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