📌  相关文章
📜  类 datetime 的对象无法转换为 int - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:55.243000             🧑  作者: Mango

代码示例1
Because $newDate is an object of type DateTime, not a string. The documentation is explicit:

Returns new DateTime object formatted according to the specified format.

If you want to convert from a string to DateTime back to string to change the format, call DateTime::format at the end to get a formatted string out of your DateTime.

$newDate = DateTime::createFromFormat("l dS F Y", $dateFromDB);
$newDate = $newDate->format('d/m/Y'); // for example