PHP:这些日期(diff?)格式参数是什么(例如%R%a) [英] PHP: What are these Date (diff?) format parameters (eg. %R%a)
问题描述
我遇到了几个例子,人们共享代码来计算两天之间的差额。
例如。
$ now = new DateTime();
$ itemDate-> diff($ now)-> format(%r%a)
但是几乎所有这些类型的帖子实际上并没有对格式参数的解释。我可以使用常规的日期格式参数,但是(例如,在这种情况下)不确定例如%r。
当在 DateTimeInterface
对象之间进行区别时, DateInterval
对象将被返回。您再也没有DateTime了,有了间隔,并且间隔的格式与DateTime对象不同。格式在此处进行了说明:
I runned into few examples where people share code for calculating the difference between two days.
Eg.
$now = new DateTime();
$itemDate->diff($now)->format("%r%a")
But almost always these types of posts don't really have an explanation about what format parameters are about. I'm okay with regular Date format parameters but (as in this case) not sure about eg. %r.
When doing difference between DateTimeInterface
objects, DateInterval
object will be returned. You don't have DateTime's anymore, you have interval, and intervals are formatted different as DateTime objects. Format is explained here: http://php.net/manual/en/dateinterval.format.php
这篇关于PHP:这些日期(diff?)格式参数是什么(例如%R%a)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!