This question already has answers here:
How to calculate the difference between two dates using PHP?
(32个答案)
4年前关闭。
我试图掌握如何获取两个mysql varchar字符串之间的区别,它们的格式为mm:ss,其中m代表分钟,s代表秒。例如。
我使用什么功能
(32个答案)
4年前关闭。
我试图掌握如何获取两个mysql varchar字符串之间的区别,它们的格式为mm:ss,其中m代表分钟,s代表秒。例如。
$a = 13:20;
$b = 13:00;
我使用什么功能
$a - $b = 00:20 ?
$a = strtotime('13:20');
$b = strtotime('13:00');
echo "The time difference between 13:20 and 13:00 is : " . ($a - $b);
Gives me
The time difference between 13:20 and 13:00 is : 1200
Kindly take note of my original format. mm:ss
最佳答案
使用strtotime()
尝试这个...
$time1 = explode(':', '13:20');
$time2 = explode(':', '13:00');
$a = 00 . ':' . $time1[0] . ':' . $time1[1];
$b = 00 . ':' . $time2[0] . ':' . $time2[1];
echo "The time difference between 13:20 and 13:00 is : " . (strtotime($a) - strtotime($b));
10-04 11:15