0
我想在存储器中存储两个小时的操作。我首先转换为毫秒,然后转换为可读的内容。它似乎工作,但最后的数字是不正确的。在这个例子中,它给了我1:30:00的差异。有人能解释为什么吗?从字符串到毫秒并返回
// I have two hours that come from a MySql database and I store in a var:
$start= "16:00:00";
$end= "16:30:00";
// I convert to milliseconds and rest:
$startMili = strtotime($start);
$endMili = strtotime($end);
$dif = $endMili - $startMili ;
// convert to something readable:
echo "<br><br> diference: ";
$readable = date("H:i:s", $dif);
echo $readable;
的_strtotime_和_DATE_功能意味着绝对时间戳,而不是间隔!额外的小时可能来自您的时区设置(_date_default_timezone_set_)。也许你可以直接在SQL查询中使用_TIMEDIFF_函数? –
当我尝试你的代码时,我得到0:30:00 – Perry
@Perry的正确结果。真奇怪。也许这是Piotr说的时区。我在巴塞罗那。你在哪? – Nrc