Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.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_Intl - Fatal编程技术网

Php 为什么我的IntlDateFormatter在错误的日期格式化?

Php 为什么我的IntlDateFormatter在错误的日期格式化?,php,datetime,intl,Php,Datetime,Intl,我试图从过去的日期格式,但显然没有这样做 问题是,该日期不只是缩短了几个小时(这可能是由于不同的时区),而是缩短了5天 这是我的示例代码: <?php $locale = "de"; $intlTimezone = \IntlTimeZone::createDefault(); $dateTimezone = $intlTimezone->toDateTimeZone(); $calendar = new \IntlGregorianCalendar($intlTimezone,

我试图从过去的日期格式,但显然没有这样做

问题是,该日期不只是缩短了几个小时(这可能是由于不同的时区),而是缩短了5天

这是我的示例代码:

<?php

$locale = "de";
$intlTimezone = \IntlTimeZone::createDefault();
$dateTimezone = $intlTimezone->toDateTimeZone();
$calendar = new \IntlGregorianCalendar($intlTimezone, $locale);
$dateFormatter = \IntlDateFormatter::create($locale, 2, -1, $intlTimezone, $calendar, "dd.MM.y");

$time = DateTimeImmutable::createFromFormat("Y-m-d", "978-12-27", $dateTimezone);
var_dump($time);
var_dump($time->format("d.m.Y"));
var_dump($dateFormatter->format($time));
最后一个值似乎是错误的。
还请注意,PHPcreateFromFormat函数似乎使用了,它将当前使用的日历应用于旧日期。日期格式似乎使用实际使用的儒略历。对于978,两者之间的差异为5天


奇怪的是,我在文档中找不到任何说明哪个类使用哪个日历,或者哪个日期被视为两个日历系统之间的截止日期。

如果这是重复的,很抱歉,但我已经搜索了问题,但我找到的都是简单的时区问题。我不确定这是否有帮助,但在978年,公历没有生效,这实际上是一个很好的观点,谢谢你@FedericoklezCulloca我想我们进入了“未定义”territory here?但是看起来PHP datetime函数应该能够根据文档中的注释处理它。日期和时间信息在内部存储为64位数字,因此支持所有可能有用的日期(包括负年份)。从过去的2920亿年到未来的2920亿年。
object(DateTimeImmutable)#5 (3) {
    ["date"]=>
    string(26) "0978-12-27 14:31:03.000000"
    ["timezone_type"]=>
    int(2)
    ["timezone"]=>
    string(3) "CET"
}
string(10) "27.12.0978"
string(9) "22.12.978"