How to get time difference in minutes in PHP

后端 未结 17 2245
独厮守ぢ
独厮守ぢ 2020-11-21 07:22

How to calculate minute difference between two date-times in PHP?

17条回答
  •  鱼传尺愫
    2020-11-21 07:50

    another way with timezone.

    $start_date = new DateTime("2013-12-24 06:00:00",new DateTimeZone('Pacific/Nauru'));
    $end_date = new DateTime("2013-12-24 06:45:00", new DateTimeZone('Pacific/Nauru'));
    $interval = $start_date->diff($end_date);
    $hours   = $interval->format('%h'); 
    $minutes = $interval->format('%i');
    echo  'Diff. in minutes is: '.($hours * 60 + $minutes);
    

提交回复
热议问题