AM PM格式的两个日期变量之间的日期差异。

时间:2012-07-12 14:14:40

标签: php

  

可能重复:
  Getting the difference between two time/dates using php?

我有两个日期变量 让$ arrival_time =“7.30 AM”;     $ departure_time =“8.30 PM”;

然后如何在php中计算这两个变量之间的时差?

2 个答案:

答案 0 :(得分:1)

<?php   
$arrival_time="7.30 AM";
$departure_time="8.30 PM";

$d1=  strtotime($arrival_time);
$d2=  strtotime($departure_time);

$diff=$d2-$d1;

//Print the difference in hours : minutes
echo date("H:i",$diff);
?>

答案 1 :(得分:0)

<?php
$am = "7:30AM";
$pm = "8:30PM";
$minutes_diff = round(abs(strtotime($pm) - strtotime($am)) / 60);