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条)

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历