php毫秒怎么转时间

参考文章:php毫秒怎么转时间?
在PHP中,你可以使用date()函数和strtotime()函数将毫秒数转换为时间。首先,将毫秒数转换为秒数,然后使用date()函数格式化时间。以下是一个示例代码:

<?php
// 毫秒数
$milliseconds = 1635939871000; // 13位毫秒数

// 将毫秒数转换为秒数(除以1000)
$seconds = $milliseconds / 1000;

// 使用date()函数将秒数格式化为日期和时间
$formattedDate = date("Y-m-d H:i:s", $seconds);

echo "毫秒数:$milliseconds<br>";
echo "转换后的时间:$formattedDate";
?>

在这个示例中,$milliseconds变量包含了13位毫秒数。首先,将毫秒数除以1000得到秒数,然后使用date()函数将秒数格式化为所需的日期和时间格式。

猜你喜欢

转载自blog.csdn.net/weixin_43187635/article/details/134241668#comments_29665484