我的代码是:
$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
它会破坏我的代码,但我不知道为什么?
答案 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');