编程语言
首页 > 编程语言> > 计算几小时和几分钟的PHP

计算几小时和几分钟的PHP

作者:互联网

好吧,所以我发送一个整数到我的mysql数据库,以毫秒为单位.现在,我试图让它说:时间播放:1天3小时15分钟.
但是我很难做到这一点,我只能得到分钟的天数和小时数,但这是总天数和总分钟数的总小时数,而不是一个小时.我的代码是这样的:

$time = $timeRow['time'];    
$seconds = floor($time / 1000);
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
$days = round($hours / 24);
$milliseconds = $time % 1000;
$seconds = $seconds % 60;
$minutes = $minutes % 60;
echo'Time Played: '.$days.' days '.$hours.' hours '.$minutes.' minutes';

任何人都可以帮我解决这个问题吗?

解决方法:

<?php

$time = $timeRow['time'] / 1000;

$days = floor($time / (24*60*60));
$hours = floor(($time - ($days*24*60*60)) / (60*60));
$minutes = floor(($time - ($days*24*60*60)-($hours*60*60)) / 60);
$seconds = ($time - ($days*24*60*60) - ($hours*60*60) - ($minutes*60)) % 60;

echo'Time Played: '.$days.' days '.$hours.' hours '.$minutes.' minutes '.$seconds.' seconds';

测试:http://codepad.viper-7.com/WBQQet

标签:php,time,milliseconds
来源: https://codeday.me/bug/20190901/1786272.html