我有一个显示时间的变量。这是从数据库中检索到的。问题是,它像这样显示:22:30:00。有没有办法在显示此变量之前对其进行格式化?我的变量名为$ time。应该是这样的:22:30
$query = "SELECT time FROM tasks";
$stm = $con->prepare($query);
$stm->execute();
$result = $stm->fetchAll(PDO::FETCH_OBJ);
echo "<table>";
foreach ($result as $pers) {
$time = $pers->time;
echo "<tr>";
echo "<td>".$time."</td>";
echo "</tr>";
}
echo "</table>";
答案 0 :(得分:0)
您可以尝试
date("H:i", strtotime($time));
答案 1 :(得分:0)
尝试一下:
engine of the car -> Linux Kernal
body parts -> GNU
interior designs -> Flavors (Mate, KDE, GNOME, XFCE)
company assemblies these together -> Distribution (let's say Debian)
@Marce也提供了此代码,但是它的$time = date('H:i', strtotime( $time ) );
函数需要时间戳作为第二个参数,可以通过strtotime完成。
请参阅文档以获取更多帮助。