我得到了这个数字:116041 (以毫秒为单位)。
我想转换成像这样的minuts:seconds:miliseconds
从理论上讲,这个数字应该转换为:1:56:xx
我正在尝试这段代码:
$diff = 116041;
$date = date("i:s:u",$diff);
echo $date;
但是我得到了下面的输出:
14:01:000000
发布于 2018-06-22 06:59:38
date()
接受一个时间戳整数。您提供的值等于Friday, January 2, 1970 8:14:01 AM
。注意到14:01
了吗?这就是您使用date("i:s:u",$diff);
得到的结果
转到Epoch Converter并在字段中输入116041
,您可以自己查看它。
发布于 2018-06-22 07:09:32
这应该是非常简单的数学运算。
// Get the minutes (60000ms per minute)
$milliseconds = 116041;
$minutes = floor(116041 / 60000);
// Find the remaining milliseconds
$milliseconds = $milliseconds % 60000;
// Continue to seconds calculation...
发布于 2018-06-22 07:22:36
在这种情况下,date
或DateTime
路由更为复杂。做一些简单的数学运算就行了。
$s = 116041 / 1000;
printf("%d:%02.3f", intdiv($s, 60), fmod($s, 60));
https://stackoverflow.com/questions/50978479
复制相似问题