转换时间戳字符串,使用的setTimestamp()。比方说,以下是我们的输入,即标记 -
$SQLTimestamp = 1600320600000;
我们希望下面的输出即日期字符串 -
2020-09-17 05:30:00
首先,从时间戳获得秒 -
$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