得到php DateInterval总共“分钟” [英] get php DateInterval in total 'minutes'

查看:128
本文介绍了得到php DateInterval总共“分钟”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在总分钟值中获取PHPDateInterval值。如何得到它?似乎简单的格式(%i分钟)不工作?

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?

以下是示例代码:

$test = new \DateTime("48 hours");
$interval = $test->diff(new \DateTime());

现在如果我尝试获得总天数的时间间隔,它的罚款:

Now if I try to get the interval in total days, its fine:

echo $interval->format('%a total days');

显示2天作为输出,这是完全正常的。如果要在总分钟中获取值,我试图得到什么,所以我试过:

It is showing 2 days as output, which is totally fine. What I am trying to get if to get the value in "total minutes", so I tried:

echo $interval->format('%i total minutes');

哪些不工作?任何帮助赞赏得到我想要的输出。

Which is not working. Any help appreciated to get my desired output.

推荐答案

abs((new \DateTime("48 hours"))->getTimestamp() - (new \DateTime)->getTimestamp()) / 60

这是获取两个 DateTime 实例之间分钟差异的最简单方法。

That's the easiest way to get the difference in minutes between two DateTime instances.

这篇关于得到php DateInterval总共“分钟”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆