如何使用 PHP 将时间转换为毫秒

How to convert a time to milliseconds using PHP

我需要将PHP时间转换成毫秒,我试过使用“time * 1000”但结果不正确。

示例时间:01:26.7(1 分 26 秒 7 毫秒)

尝试拆分部分并将每个部分转换为毫秒,然后 return 求和,例如:

$time1   = explode(":", "01:26.7");
$time2   = explode(".", $time1[1]);

$minute  = $time1[0] * 60 * 1000;
$second  = $time2[0] * 1000;
$milisec = $time2[1];

$result = $minute + $second + $milisec;

echo $result;

Live working example

您可以使用 DateTime class 或一个库,检查:

Convert date to milliseconds in laravel using Carbon