【问题标题】:Can we use add time to the PHP date() function?我们可以在 PHP date() 函数中使用添加时间吗?
【发布时间】:2011-02-25 02:11:14
【问题描述】:

我正在尝试从当前时间制定时间表 到 12 小时后。我正在使用 date() 函数 检索当前时间,但如何增加 小时和调整上午/下午?我可以在 date() 上加 1 功能?

感谢您的帮助。

【问题讨论】:

    标签: php date increment hour


    【解决方案1】:
    $now = time();
    $then = $now + 12 * 60 * 60;
    echo date(format, $then);
    

    【讨论】:

      【解决方案2】:

      你可以使用strtotime:

      date('d-m-Y H:i:s', strtotime('+1 hour')); // one hour since now
      

      date('d-m-Y H:i:s', strtotime('2011-02-25 14:00:42'));
      

      【讨论】:

        【解决方案3】:
        $mydate = date("dateformat", time() + 43200);
        

        time() 获取当前时间戳,然后添加 43200 即 12 小时 * 60 分钟 * 60 秒

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-04-04
          • 1970-01-01
          • 2016-04-08
          • 2012-06-17
          • 2011-04-19
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多