I'm trying to convert a date format using the DateTime function. The date data is taken from an external XML file, how can I convert the data intro a string in the DateTime function?
我正在尝试使用DateTime函数转换日期格式。日期数据来自外部XML文件,如何在DateTime函数中将数据转换为字符串?
Here's the code:
这是代码:
echo "Date: " . $date = new DateTime((string)$info->channel[0]->item[0]->pubDate); echo $date->format("d-m-Y H:m") . "<br />";
This is the error: Catchable fatal error: Object of class DateTime could not be converted to string in
这是错误:可捕获的致命错误:类DateTime的对象无法转换为字符串
Something I'm forgetting?
我忘记了什么?
1 个解决方案
#1
0
You are using string concantation with a datetime object. You need to convert the date to a string before trying to echo it:
您正在使用字符串concantation与datetime对象。在尝试回显之前,您需要将日期转换为字符串:
$date = new DateTime((string)$info->channel[0]->item[0]->pubDate);
echo "Date: " . $date->format("d-m-Y H:m") . "<br />";
#1
0
You are using string concantation with a datetime object. You need to convert the date to a string before trying to echo it:
您正在使用字符串concantation与datetime对象。在尝试回显之前,您需要将日期转换为字符串:
$date = new DateTime((string)$info->channel[0]->item[0]->pubDate);
echo "Date: " . $date->format("d-m-Y H:m") . "<br />";