zoukankan      html  css  js  c++  java
  • php函数strtotime结合date时间修饰语的使用

    下面简单介绍在项目开发中date时间函数和strtotime所遇到的问题,以及解决办法。

    原文地址:小时刻个人技术博客 > http://small.aiweimeng.top/index.php/archives/strtotime.html

    在项目中经常会用到时间查询,根据时间范围去查找数据。
    下面简单介绍一下在项目中我遇到的问题;
    在搜索栏中有这么几个选项,```今天,昨天,最近7天,上一月```,通过这几个时间查出不同数据,
    但是项目中使用strtotime的时候一般出现问题,
    eg:我在11-30号查询上一个月数据的时候只出现了到10-30号的数据,

     strtotime("-1 month");

    但是10月有31天啊,检查了半天没什么问题啊。这是咋回事。我靠。

    有问题找百度(●'◡'●),找到一篇博客[地址]:说php5.3以后增加了一些date的修正语,”first day of” 和 “last day of”,
    然后按照博文说的进行了修改,果然数据出来了。
    下面直接贴他的例子,:D
    `

    var_dump(date("Y-m-d", strtotime("last day of -1 month", strtotime("2017-03-31"))));
    //输出2017-02-28
    var_dump(date("Y-m-d", strtotime("first day of +1 month", strtotime("2017-08-31"))));
    ////输出2017-09-01
    var_dump(date("Y-m-d", strtotime("first day of next month", strtotime("2017-01-31"))));
    ////输出2017-02-01
    var_dump(date("Y-m-d", strtotime("last day of last month", strtotime("2017-03-31"))));
    ////输出2017-02-28
  • 相关阅读:
    ConcurrentSkipListMap 源码分析
    ConcurrentHashMap 源码分析
    CopyOnWriteArrayList 源码分析
    AtomicBoolean 源码分析
    commons-lang3-3.4.jar
    Effective Java
    FindBugs Bug Descriptions
    EasyMock
    Apache Maven 入门
    Eclipse
  • 原文地址:https://www.cnblogs.com/smallKilts/p/10173623.html
Copyright © 2011-2022 走看看