错误:无法将类DateTime的对象转换为string

时间:2022-10-22 18:32:08

I am getting an error with displaying the value:

我在显示值时出错:

$thedate = $row2['date'];
echo $thedate;

In php, which is a value from the database ($thedate) is "2015-05-05 21:52:31.000"

在php中,它是来自数据库的值($thedate)是“2015-05 21:52:31.000”

How can I format it to be able to display it on the php page as a string? Currently it shows error "Object of class DateTime could not be converted to string".

如何将其格式化,使其能够以字符串形式显示在php页面上?目前它显示错误“类DateTime不能转换为string”。

1 个解决方案

#1


5  

You have a DateTime object, so you have to use format() to format your output, e.g.

你有一个DateTime对象,所以你必须使用format()来格式化你的输出。

echo $thedate->format("Y-m-d");

#1


5  

You have a DateTime object, so you have to use format() to format your output, e.g.

你有一个DateTime对象,所以你必须使用format()来格式化你的输出。

echo $thedate->format("Y-m-d");