DateTime类的对象无法转换为字符串

我在一个名为Film_Release的字段中有一个表,该表的字符串值格式为 年 (

我正在遍历,我想在日期时间将它们转换并将其推出到另一个表中。我的第二张表有一个名为Films_Date的列,其格式为DATE。我收到此错误

$dateFromDB = $info['Film_Release'];

$newDate = DateTime::createFromFormat("l dS F Y",$dateFromDB); //( http:php.net/manual/en/datetime.createfromformat.php)

然后,我通过插入命令将$ newdate插入表中。

为什么会出现这样的错误?

回答:

因为$newDate是类型的对象DateTime,而不是字符串。该文档是明确的:

返回DateTime根据指定格式设置格式的新对象。

如果要从字符串转换DateTime回字符串以更改格式,请DateTime::format最后调用以从中获取格式化的字符串DateTime

$newDate = DateTime::createFromFormat("l dS F Y", $dateFromDB);

$newDate = $newDate->format('d/m/Y'); // for example

以上是 DateTime类的对象无法转换为字符串 的全部内容, 来源链接: utcz.com/qa/398677.html

回到顶部