zoukankan      html  css  js  c++  java
  • 获取一个想要的日期,时间

      很重要的函数:strtotime()

      比如获取某个时间一周前日期应该是什么?

    1 //当前时间
    2 $nowDate = "2017-01-01 00:00:00";
    3 $lastWeek = date('Y-m-d H:i:s' , strtotime('-1 week ', strtotime($nowDate)));
    4 echo '上周的日期时间为:'.$lastWeek;

      获取一天前,一月前,一年前方法也是如此

    //1天前
    $lastDayDate = date("Y-m-d H:i:s", strtotime('-1 day', strtotime($dtE)));
    //1月前
    $lastMonthDate = date("Y-m-d H:i:s", strtotime('-1 month', strtotime($dtE)));
    //1年前
    $lastYearDate = date("Y-m-d H:i:s", strtotime('-1 year', strtotime($dtE)));

      注意:strtotime()函数,

        1.如果只有一个参数,即获取某个日期的时间戳;

        2.如果有两个参数,则第二个参数应该是时间戳格式;

  • 相关阅读:
    C语言第五次作业
    C语言第四次作业
    C语言第三次作业

    第一次作业
    C语言第五次作业
    C语言第四次作业
    C语言第三次作业
    C语言理论作业—2
    燕勇鹏-160809318
  • 原文地址:https://www.cnblogs.com/wxdblog/p/7850949.html
Copyright © 2011-2022 走看看