php - DateInterval 中的天数和 "d"属性有什么区别

标签 php datetime

当我使用 DateInterval 类时,它返回一个名为“d”的属性,然后返回另一个名为“Days”的属性,我真的很困惑这两者之间的区别。有人可以解释一下吗。

下面是我的代码中返回的对象的示例。

DateInterval(
y =
0
m =
1
d =
1
h =
3
i =
16
s =
6
weekday =
0
weekday_behavior =
0
first_last_day_of =
0
invert =
1
days =
31
special_type =
0
special_amount =
0
have_weekday_relative =
0
have_special_relative =
0

最佳答案

  • d - 添加月份后需要添加的从月初的天数 - (Feb 23 - Jan 1).d == 22)
  • days - 总天数 - (Feb 23 - Jan 1).days == 31 + 22)

来自 the documentation :

d

Number of days.

days

If the DateInterval object was created by DateTime::diff(), then this is the total number of days between the start and end dates. Otherwise, days will be FALSE.

Before PHP 5.4.20/5.5.4 instead of FALSE you will receive -99999 upon accessing the property.

关于php - DateInterval 中的天数和 "d"属性有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30446918/

相关文章:

php - 使用 pdo 按名称对行组求和

php - 使用 PHP 重写 URL

php - 关系划分SQL

MySql Null DateTime 和 MS.net 表现不佳

c# - 获取一个月中的第 x 个最后一个工作日(不是假期)

java - 在特定时间之间重定向到 HTML 页面的脚本

javascript - Websocket 在刷新时不连接

c# - 如果 DateTime.Now 不够好怎么办?

c# - 如何在 C# 中使用 AddYears 方法获取 2 月 29 日

php - 简单的 PHP/MySQL ORM 代码不执行