【发布时间】:2017-04-19 10:21:56
【问题描述】:
我正在尝试使用子午线将时间字符串转换为日期时间,但日期时间错误。
这是我的代码:
$timeZone = 'Europe/Warsaw';
date_default_timezone_set($timeZone);
$millis = 1540399680000;
$seconds = $millis / 1000;
$date = date("d/m/Y H:i:s a", $seconds);
debug($date);
$timeZone = new DateTimeZone('Europe/Warsaw');
$formato = "d/m/Y H:i:s a";
$fecha = DateTime::createFromFormat($formato, $date, $timeZone);
debug($fecha);
debug($fecha->format('Y'));
debug($fecha->format('a'));
调试结果($date)
24/10/2018 18:48:00 pm
调试结果($fecha)
object(DateTime) {
date => '2018-10-25 06:48:00.000000'
timezone_type => (int) 3
timezone => 'Europe/Warsaw'
}
我期待的是 debug($fecha);
date => '2018-10-24 06:48:00.000000'
【问题讨论】:
-
你期望得到什么?
-
$fecha是一个日期时间对象,你可以根据需要格式化。 -
debug($fecha->format('d/m/Y H:i:s a'));它会给你想要的解决方案