• php 当前日期加一天和指定日期加一天


    1.给当前时间加一天?一小时?

    <?php
    echo "今天:",date('Y-m-d H:i:s'),"<br>";
    echo "明天:",date('Y-m-d H:i:s',strtotime('+1 day'));
    ?>

    上一行输出当前时间,下一行输出明天时间
    同理加一年,一小时,一分钟 ,一月。。。

    echo "明天:",date('Y-m-d H:i:s',strtotime('+1 day'));

    echo "明天:",date('Y-m-d H:i:s',strtotime('+1 hour'));

    echo "明天:",date('Y-m-d H:i:s',strtotime('+1 minute'));

    echo "明天:",date('Y-m-d H:i:s',strtotime('+1 mouth'));

    这里+1 day可以修改参数1为任何想需要的数  day也可以改成year(年),month(月),hour(小时)minute(分),second(秒)如:
    date('Y-m-d H:i:s',strtotime("+1 day +1 hour +1 minute");
    可以随便自由组合,以达到任意输出时间的目的
    注:该方法之针对1970年以后试用,也就是时间戳的适用范围。

    2.给指定时间加一天?一小时?.。。。。。

     echo   date("Y-m-d",strtotime("+1 month",strtotime("2012-02-04")));

    结果为:2011-03-04

    echo   date("Y-m-d",strtotime("+1 week",strtotime("2011-02-04")));

    结果为:2011-02-11

    echo   date("Y-m-d",strtotime("+1 day",strtotime("2011-02-04")));

    结果为:2011-02-05

    其它同理如上。

    注:该方法之针对1970年以后试用,也就是时间戳的适用范围。

  • 相关阅读:
    springboot之静态资源放行的方法(记录)
    FastDFS之图片上传
    FastDFS安装部署
    Docker安装MySQL5.7.25
    123qwe
    Spring3 MVC 注解(一)---注解基本配置及@controller和 @RequestMapping 常用解释
    jQuery可见性过滤选择器
    jQuery属性过滤选择器
    jQuery内容过滤选择器
    jQuery子元素过滤选择器
  • 原文地址:https://www.cnblogs.com/bwteacher/p/9663475.html
Copyright © 2020-2023  润新知