【发布时间】:2017-02-19 20:03:46
【问题描述】:
考虑这两个日期 2017/4/14、2017/6/3
在 php 中使用 date_diff 给了我这个
object(DateInterval)[6]
public 'y' => int 0
public 'm' => int 1
public 'd' => int 20
public 'h' => int 0
public 'i' => int 0
public 's' => int 0
public 'weekday' => int 0
public 'weekday_behavior' => int 0
public 'first_last_day_of' => int 0
public 'invert' => int 0
public 'days' => int 50
public 'special_type' => int 0
public 'special_amount' => int 0
public 'have_weekday_relative' => int 0
public 'have_special_relative' => int 0
我的任务是创建此函数的副本(作为作业)。但是当我通过我的算法运行这些日期时,我得到了
object(stdClass)[4]
public 'years' => int 0
public 'months' => int 1
public 'days' => int 19
public 'total_days' => int 50
public 'invert' => int 0
当我手动(手动)计算天数时,我仍然认为这是额外的 19 天。我不是在寻找分配解决方案。但也许某些算法或 date_diff 函数有一些我不知道的错误?
对于 200 多个测试用例,我的算法有效,对于其他 7 个则无效,而且我的解决方案和 php 解决方案之间总是有天差地别。
【问题讨论】: