Calculate elapsed time in php

后端 未结 4 757
既然无缘
既然无缘 2020-12-13 19:01

Hi All I\'m trying to calculate elapsed time in php. The problem is not in php, it\'s with my mathematical skills. For instance: Time In: 11:35:20 (hh:mm:ss), now say the

4条回答
  •  [愿得一人]
    2020-12-13 19:05

    Using PHP >= 5.3 you could use DateTime and its method DateTime::diff(), which returns a DateInterval object:

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    

提交回复
热议问题