get php DateInterval in total 'minutes'

前端 未结 5 545
鱼传尺愫
鱼传尺愫 2020-12-15 03:21

I am trying to get the PHP \"DateInterval\" value in \"total minutes\" value. How to get it? Seems like simple format(\"%i minutes\") not working?

Here is the sampl

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 03:54

    I wrote two functions that just calculates the totalTime from a DateInterval. Accuracy can be increased by considering years and months.

    function getTotalMinutes(DateInterval $int){
        return ($int->d * 24 * 60) + ($int->h * 60) + $int->i;
    }
    
    function getTotalHours(DateInterval $int){
        return ($int->d * 24) + $int->h + $int->i / 60;
    }
    

提交回复
热议问题