douzhao7445 2017-08-13 17:52
浏览 117
已采纳

如何在PHP 24小时格式中扣除时间

How to subtract 00:00:00 example with 1 hour?

I've tried:

$minus1=strtotime(00:00:00)-strtotime('-1 hour');

but instead of an answer of 23:00:00, I got -1502671524 instead.

  • 写回答

1条回答 默认 最新

  • dooid3005 2017-08-13 18:19
    关注

    You can use DateTime and DateInterval option to do in PHP.

        $date = new DateTime('00:00:00');
        $date->sub(new DateInterval('PT1H00M'));
        echo $date->format('H:i:s') . "
    ";
    
    

    The P stands for Period. The T stands for Timespan. H stands for Hour to reduce and finally M stands for Minutes to reduce.

    See DateTime, DateTime::sub, and DateInterval in the PHP manual. You'll have to set the DateTime to the appropriate date and time, of course.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部