Php 如何修剪时间戳(我知道,以前有人问过……)

Php 如何修剪时间戳(我知道,以前有人问过……),php,datetime,timestamp,trim,Php,Datetime,Timestamp,Trim,我的服务器响应日期/时间戳为XML格式,如下所示: <au_updated_date>2018-02-04T13:32:58</au_updated_date> date('Y-m-d', strtotime('2018-02-04T13:32:58')) 还尝试了一些修剪、字符串和子字符串函数,但均无效:( 帮个忙 编辑: 仍然不起作用:( 也许这会有用: $response = curl_exec($ch); $data = json_decode($respon

我的服务器响应日期/时间戳为XML格式,如下所示:

<au_updated_date>2018-02-04T13:32:58</au_updated_date>
date('Y-m-d', strtotime('2018-02-04T13:32:58'))
还尝试了一些修剪、字符串和子字符串函数,但均无效:(

帮个忙

编辑:

仍然不起作用:(

也许这会有用:

$response = curl_exec($ch);
$data = json_decode($response,true);
然后循环通过响应并显示在html表中

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

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

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

您可以使用strip_标记删除XML。
然后使用strotime获取字符串的Unix时间。
然后使用date对其进行分析,以适应需要

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

Echo date("Y-m-d", strtotime(strip_tags($str)));
$str=“2018-02-04T13:32:58”;
回音日期(“Y-m-d”,STROTIME(带标签($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。

看起来OP需要一个正则表达式来提取实际值,以便与Strotime一起使用。
@Martin为什么需要正则表达式?@Andreas以及正则表达式可能有些过火,但需要删除字符串的
方面。该
部分称为HTML或XML,由国家税务局删除ve php函数strip_tags()@Martin@Andreas根据输入数据的可靠性,我可能不建议使用
strip_标签
,因为这样一来,部分或损坏的标签可能会导致删除比预期更多的数据。