如何 trim 时间戳(我知道,之前被问过......)

How to trim the timestamp (i know, been asked before....)

我的服务器响应 date/timestamp 是 XML 格式,如下所示:

<au_updated_date>2018-02-04T13:32:58</au_updated_date>

我只要2018-02-04

试过这个但是什么都不显示:

[date_format("au_updated_date","Y-m-d")]

也尝试了一些trim,字符串和子字符串函数无济于事:(

赞成?

编辑:

还是不行:(

也许这可能有用:

$response = curl_exec($ch);
$data = json_decode($response,true);

然后遍历响应并在 html table 中显示。

echo '<td align=left style="text-align:left">', ($data["results"][$i]["card"]["au_updated_date"]), '</td>';

您可以像这样解析和格式化它:

date('Y-m-d', strtotime('2018-02-04T13:32:58'))

您可以使用 strip_tags 删除 XML。
然后使用strtotime获取字符串的Unix时间。
然后使用日期解析它以适应它。

$str = "<au_updated_date>2018-02-04T13:32:58</au_updated_date>";

Echo date("Y-m-d", strtotime(strip_tags($str)));

天哪,我明白了!

只用了大约 4 个小时就搞定了哈哈

而不是这个:

$au_dates = $au_record->getElementsByTagName( "au_updated_date" );
$au_date = $au_dates->item(0)->nodeValue;

我这样做了:

$au_dates = $au_record->getElementsByTagName( "au_updated_date" );
$au_date = $au_dates->item(0)->nodeValue;
$new_date = date("Y-m-d", strtotime($au_date));

谢谢大家,尤其是 Andreas。