DateTime打破代码PHP

时间:2017-08-20 23:38:10

标签: php

我的代码是:

$etime = $arr['od'];
$ds = date("Y-m-d H:i:s", strtotime($etime));
$timezone=new DateTimeZone("UTC"); // declare whatever your timezone is
$etimed=new DateTime($ds,$timezone);  // resultset datetime

$arr['od']2017-08-20 19:05:59,试图回复$etimed它会破坏我的代码,但我不知道为什么?

1 个答案:

答案 0 :(得分:4)

Datetime是一个对象,它不能像那样回显,因此您需要格式化datetime以像下面的代码一样回显它:

$etime = $arr['od'];

$ds = date("Y-m-d H:i:s", strtotime($etime));

$timezone=new DateTimeZone("UTC"); // declare whatever your timezone is
$etimed=new DateTime($ds,$timezone);  // resultset datetime

echo $etimed->format('Y-m-d H:i:s');