我有一个日期转换的问题,经过很多测试后,我不明白我错过了什么。
我从存储在MySQL数据库中的典型日期时间开始(2019-12-31 09:35:16)。
更准确地说,我在Windows上使用PHP7.2.10
下面是一个简单的例子:
$formatter = new IntlDateFormatter(
'fr-FR',
IntlDateFormatter::NONE,
IntlDateFormatter::NONE,
new DateTimeZone('Europe/Paris'),
IntlDateFormatter::GREGORIAN,
'd/M/Y HH:mm \'UTC\'XXX'
);
echo $formatter->format(new \DateTime('2019-12-31 09:35:16'));答案给了我31/12/2020 09:35 UTC+01:00而不是31/12/2019 09:35 UTC+01:00。
经过一些尝试,2013年和2025年也出现了这一变化(很可能每六年发生一次.)。
我做错了什么?
发布于 2020-01-10 14:02:31
这是一种不同的格式。它不使用PHP日期格式,它使用ICU数据格式。y/Y格式不同:
Date Field Symbol Table
Symbol Meaning Example(s)
y year (yy or y or yyyy) 96 or 1996
Y year of "Week of Year" Y 1997由于2019-12-31是一个星期二,它属于2020年的周年.相反,您将使用y作为格式。
$formatter = new IntlDateFormatter(
'fr-FR',
IntlDateFormatter::NONE,
IntlDateFormatter::NONE,
new DateTimeZone('Europe/Paris'),
IntlDateFormatter::GREGORIAN,
'd/M/y HH:mm \'UTC\'XXX'
);
echo $formatter->format(new \DateTime('2019-12-31 09:35:16'));https://stackoverflow.com/questions/59682843
复制相似问题