将来自 SQL 数据库的时间戳转换为 PHP 字符串?
phpserver side programmingprogrammingmysql更新于 2026/1/24 16:12:17
要将时间戳转换为字符串,请使用 setTimestamp()。假设以下是我们的输入,即时间戳 −
$SQLTimestamp = 1600320600000;
我们想要以下输出,即日期字符串 −
2020-09-17 05:30:00
首先从 Timestamp 中获取秒数 −
$seconds = round($SQLTimestamp/1000, 0);
示例
<!DOCTYPE html>
<html>
<body>
<?php
$SQLTimestamp = 1600320600000;
$seconds = round($SQLTimestamp/1000, 0);
$PHPDateObject = new DateTime();
$PHPDateObject->setTimestamp($seconds);
echo $PHPDateObject->format('Y-m-d H:i:s');
?>
</body>
</html>
输出
2020-09-17 05:30:00
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

