dongleiwei2182 2014-08-13 09:30
浏览 40

PHP使用小时和分钟减去日期

Hi I've search the internet about this topics and seems can't give me the right ouput? What could I be doing doing wrong? I want to output the remaining days from an expiration period with hours and minutes.

Here's what I've done,

$date_expire = '2014-09-12 23:59:59';  
$date = new DateTime($date_expire);
$now =  new DateTime();
echo $date->diff($now)->format("%d days, %H hours and %i minutes");

I am from the philippines and the current date and time I wrote this is August 13, 2014 5:26pm the ouput gives me 29 days, 12 hours and 30 minutes. Which is think is wrong? Can you help me? thanks!

  • 写回答

2条回答 默认 最新

  • douao2019 2014-08-13 10:25
    关注

    your source code is working fine and it does what you expect.

    yes, on that date was missed 29 days 12 hours and 30 minutes and a few months.

    the problem is that you don't print out the months (:

    here, there is your script with the months included:

    // this is your start date
    $date_expire = "2014-09-12 23:59:59";
    // build a DateTime instance from it
    $date = new DateTime($date_expire);
    // another instance for the date of NOW
    $now =  new DateTime();
    // print the difference with %m (months) included
    echo $date->diff($now)->format("%m months, %d days, %H hours and %i minutes");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料