Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中格式化时间戳的日期输出_Php - Fatal编程技术网

在php中格式化时间戳的日期输出

在php中格式化时间戳的日期输出,php,Php,我使用以下php命令在网页上显示数据库系统(postgresql)表中的时间戳 while ($column = pg_fetch_array($result)) { echo "<tr>"; echo "<td>".$column[0]."</td>"; echo "</tr>"; } while($column=pg\u fetch\u数组($result)){ 回声“; 回显“$列[0]”; 回声“; } 但是时间

我使用以下php命令在网页上显示数据库系统(postgresql)表中的时间戳

while ($column = pg_fetch_array($result)) {
    echo "<tr>";
    echo "<td>".$column[0]."</td>";
    echo "</tr>";
}
while($column=pg\u fetch\u数组($result)){
回声“;
回显“$列[0]”;
回声“;
}
但是时间戳格式太详细了,我如何简化它的显示格式,例如“2014-04-18 18:29”

当前输出类似于2014-04-18 18:07:36.978
提前感谢您的帮助。

如果您有时间戳,如
Thu,2000年12月21日16:01:07+0200
(或类似),您可以使用
date
strotime

echo date('Y-m-d H:i:s', strtotime($column[0]));
或者,如果使用PHP 5.2+,则可以使用以下类:


“但是时间戳格式太详细了”-它到底输出了什么?您是否尝试使用
strotime()
?$column[0]显示为输出的内容是什么?
$dateTime = new DateTime($column[0]);
echo $dateTime->format('Y-m-d H:i:s');