get php DateInterval in total 'minutes'

前端 未结 5 534
鱼传尺愫
鱼传尺愫 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 04:00

    Here is the excepted answer as a method in PHP7.2 style:

    /**
     * @param \DateTime $a
     * @param \DateTime $b
     * @return int
     */
    public static function getMinutesDifference(\DateTime $a, \DateTime $b): int
    {
        return abs($a->getTimestamp() - $b->getTimestamp()) / 60;
    }
    

提交回复
热议问题