【问题标题】:Date difference between two date variables with AM PM format. [duplicate]AM PM 格式的两个日期变量之间的日期差异。 [复制]
【发布时间】:2012-07-12 14:14:39
【问题描述】:

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

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

那么如何计算php中这两个变量的时间差呢?

【问题讨论】:

    标签: php


    【解决方案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);
    ?>
    

    【讨论】:

      【解决方案2】:
      <?php
      $am = "7:30AM";
      $pm = "8:30PM";
      $minutes_diff = round(abs(strtotime($pm) - strtotime($am)) / 60);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-16
        • 2016-10-31
        • 1970-01-01
        • 2011-10-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多