在php中格式化时间戳的日期输出
我使用以下php命令在网页上显示数据库系统(postgresql)表中的时间戳在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]”; 回声“; } 但是时间
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');