代码很简单,我想使用 IntlDateFormatter 将字符串转换为 DateTime 对象,但是结果与原始结果完全不同。我做错了什么?以下代码是基于构造DateTimeToLocalizedStringTransformer的Symfony4.3
<?php
//turn string to timestamp
$t = new \IntlDateFormatter('en_US', 2, 2, new DateTimeZone('Asia/Shanghai') , 1, 'Y-m-d H:i:s');
$t->setLenient(false);
$timestamp = $t->parse('2019-09-18 18:58:08');
//turn timestamp back to string
$date = new DateTime();
$date->setTimestamp($timestamp);
$date->setTimezone(new \DateTimeZone('Asia/Shanghai'));
echo $date->format('Y-m-d H:i:s') . "\n"; //output : 2019-01-18 18:09:00, why?
翻阅古今
UYOU