doupin5408 2017-08-17 15:26
浏览 38
已采纳

PHP在x小时后更改日期

In my code I am successful to display current date but my requirement is to show next day date after 3 hours e.g. 2017-08-17 20:00:00 the next date will be 2017-08-18 but it will show next date after spending 3 hours i.e. 2017-08-18 03:00:00 until that it remain show the old date.

I am able to add 3 hours to current date/time but I don't know how to show it after 3rd hour of the next date. Here is my code

<?php
date_default_timezone_set('Asia/Kolkata');
$time_add = date("Y-m-d H:i:s", strtotime('+3 hours'));
$time_now = date("Y-m-d H:i:s");
echo $time_now;
?> 
  • 写回答

1条回答 默认 最新

  • douwang6635 2017-08-17 15:34
    关注

    echo date("Y-m-d H:i:s", strtotime('+3 hours'));

    The problem with your code is that you were assigning this to a variable called $time_add but then doing nothing with it.

    If you want to print the current date/time after it, just use it without +3 hours:

    echo date("Y-m-d H:i:s");

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

报告相同问题?

悬赏问题

  • ¥15 questasim仿真报错
  • ¥15 寻找电脑攻防的导师,有问题请教一下。
  • ¥20 微信同是win11,我的电脑安装不了pageoffice,一直无法打开
  • ¥15 这个界面我通过postman请求不到,但是通过浏览器可以正常访问
  • ¥15 动态规划算法实现背包问题
  • ¥15 wpf程序使用过程中异常奔溃
  • ¥15 多目标优化算法在与其他算法数据对比结果判断
  • ¥15 CPTN和EAST,主干网络是VGG16,请问在ICDAR2015数据集上训练之后,CPTN和EAST模型的大小为多少
  • ¥15 按颜色进行点云分割-python
  • ¥15 Matlab如何实现汽车变道切入场景的批量仿真