zoukankan      html  css  js  c++  java
  • PHP获取本月起始和终止时间戳

    一、本月起始和结束

    //获取本月开始的时间戳
    $beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
    //获取本月结束的时间戳
    $endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
    View Code

    二、上月起始和结束

         写法一:

    $m = date('Y-m-d', mktime(0,0,0,date('m')-1,1,date('Y'))); //上个月的开始日期
            $t = date('t',strtotime($m)); //上个月共多少天
    
            $start = date('Y-m-d', mktime(0,0,0,date('m')-1,1,date('Y'))); //上个月的开始日期
            $end = date('Y-m-d', mktime(0,0,0,date('m')-1,$t,date('Y'))); //上个月的结束日期
            //echo 15*24*3600;
            //echo 30*24*3600;
    
            $time=strtotime($start);
            dump(date('Y-m-d H:i:s',$time));//2017-06-01 00:00:00
            $jieshu=strtotime($end);
            dump(date('Y-m-d H:i:s',$jieshu));//2017-06-30 00:00:00

         写法二:

    $thismonth = date('m');
            $thisyear = date('Y');
            if ($thismonth == 1) {
             $lastmonth = 12;
             $lastyear = $thisyear - 1;
            } else {
             $lastmonth = $thismonth - 1;
             $lastyear = $thisyear;
            }
            $lastStartDay = $lastyear . '-' . $lastmonth . '-1';
            $lastEndDay = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay));
            $b_time = strtotime($lastStartDay);//上个月的月初时间戳
            $e_time = strtotime($lastEndDay);//上个月的月末时间戳2017-06-30 00:00:00(注意 是最后一天的开始时间点)
  • 相关阅读:
    为jquery添加扩展标准思路
    linux 相关命令
    通过设置PHPSESSID保存到cookie实现免登录
    CentOs7 配置nfs 系统
    ajax 异步 跨域上传图片
    php下载并安装pear脚本
    php基于swoole扩展的WebSocket
    php冒泡排序
    微信公众号验证TOKEN
    CSS清浮动处理(Clear与BFC)
  • 原文地址:https://www.cnblogs.com/meetuj/p/7112493.html
Copyright © 2011-2022 走看看