如何在PHP中以秒为单位获得时间差异? [英] How to get difference of a time in seconds in PHP?
本文介绍了如何在PHP中以秒为单位获得时间差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据类型为time"的数据库列,它存储 11:30:45.这次我在一个变量中提取了
I have a database column with datatype "time" which stores 11:30:45. I have fetched this time in a variable say
$databasetime = 11:30:45
我想声明一个变量,比如 $currenttime
,它将包含刚才的时间.就像现在的 11:33:30 一样,另一个变量将包含它们之间的差异,如
I want to declare a variable say $currenttime
which will contain time just now. Like its 11:33:30 right now and another variable which will contain their difference in seconds like
$timediff = $currenttime - $databasetime;
echo $timediff;
我正在尝试 $currenttime = time();
但我没有得到我想要的结果.我想要 $timediff = 165
但是当我回显 time() 时,我得到了一个非常大的值.
I am trying $currenttime = time();
but I am not getting the result which I desire. I want $timediff = 165
but when I echo time(), I am getting a very big value.
推荐答案
$databasetime = strtotime('11:30:45');
$curtime = time();
echo $curtime - $databasetime;
这篇关于如何在PHP中以秒为单位获得时间差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文