php中的时间计算

时间:2012-08-28 15:54:47

标签: php

我需要在php

中区分这两个值
1 = ** 12:10:am **

2 = ** 10:11:pm **

4 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

试试这个:

减去时间:(分钟小时数)

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;
}

答案 2 :(得分:0)

继承人可能有所帮助

$future = strtotime('21 July 2013');
$timefromdb = //source time you have to define
$timeleft = $future-$timefromdb;
$daysleft = round((($timeleft/24)/60)/60);

答案 3 :(得分:0)

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