Calculate the difference between date/times in PHP

前端 未结 5 1404
名媛妹妹
名媛妹妹 2020-12-11 19:17

I have a Date object ( from Pear) and want to subtract another Date object to get the time difference in seconds.

I have tried a few things but the first just gave

5条回答
  •  一整个雨季
    2020-12-11 19:27

    Still gave somewhat wrong values but considering I have an old version of PEAR Date around, maybe it works for you or gives you an hint on how to fix :)

    setTZByID("US/Hawaii");
      $target->convertTZByID("America/Sao_Paulo");
    
      $diff = new Date_Span($target,$now);
    
      echo "Now (localtime): {$now->format("%Y-%m-%d %H:%M:%S")} \n\n";
      echo "Target (localtime): {$target->format("%Y-%m-%d %H:%M:%S")} \n\n";
      echo $diff->format("Diff: %g seconds => %C");
    ?>
    

提交回复
热议问题