我需要在 php 中得到这两个值之间的区别
1 = ** 12:10:am **
2 = ** 10:11:pm **
试试这个:
减去时间:(小时加分钟)
function subtractTime($initialHour, $finalHour){
return (date("H:i", strtotime("00:00") + strtotime($finalHour) - strtotime($initialHour)));
}
减去时间:(小时加上分钟和秒)
function subtractTime($initialHour, $finalHour){
return (date("H:i:s", strtotime("00:00:00") + strtotime($finalHour) - strtotime($initialHour)));
}
求和时间:
function sumTime($initialHour, $finalHour) {
$h = date('H', strtotime($finalHour));
$m = date('i', strtotime($finalHour));
$s = date('s', strtotime($finalHour));
$tmp = $h." hour ".$m." min ".$s." second";
$sumHour = $initialHour." + ".$tmp;
$newTime = date('H:i:s', strtotime($sumHour));
return $newTime;
}
继承人的东西可能会有所帮助
$future = strtotime('21 July 2013');
$timefromdb = //source time you have to define
$timeleft = $future-$timefromdb;
$daysleft = round((($timeleft/24)/60)/60);
function timeToMinutes($time) {
$time = explode(':', $time);
return (($time[2]=='pm')?($time[0]+12):$time[0])*60+$time[1];
}
$diff = timeToMinutes('10:11:pm') - timeToMinutes('12:10:am');
echo $diff; //difference in minutes