PHP Add Up Hours, Minutes, Seconds

后端 未结 4 1070
清歌不尽
清歌不尽 2020-12-11 22:19

Given a series of hours, minutes, and seconds (ex: 01:30:00 or 00:30:00), I would like to add up each and convert the sum to seconds.

For example, if the total time

4条回答
  •  一个人的身影
    2020-12-11 22:53

    Try this:

    $string = "1:30:20";
    $components = explode(":", $string);
    $seconds = $components[0]*60*60 + $components[1]*60 + $components[2]
    

提交回复
热议问题