dtuqxb3884 2013-10-10 08:39
浏览 51
已采纳

Datetime diff返回奇怪的输出

I'm using DateTime and diff to compute the difference in days between two dates as follows:

$data_inceput = '2013-10-01';
$data_sfarsit = '2013-10-31';
$date1 = new DateTime($data_inceput);
$date2 = new DateTime($data_sfarsit);

$nr_zile = $date2->diff($date1)->format("%a");

$nr_zile comes out as 6015 for some reasons.

If I `var_dump($date2->diff($date1));

i get:

object(DateInterval)#6 (8) {
   ["y"] => int(0)
   ["m"] => int(0)
   ["d"] => int(30)
   ["h"] => int(0)
   ["i"] => int(0)
   ["s"] => int(0)
   ["invert"] => int(1)
   ["days"] => int(6015)

Any idea why it's behaving this way? I've also tried to set the timezone to UTC to each date individually and get the same result.

edit: I tested on the production server and it works great, the only problem is on local apache server but the php settings are basically identical between the two.

  • 写回答

2条回答 默认 最新

  • douxun3496 2013-10-10 09:02
    关注

    this is a problem of Windows https://bugs.php.net/bug.php?id=51184

    upgrade to the latest php version or use any alternate solution for this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?