zoukankan      html  css  js  c++  java
  • php获取 本月 本周 或者 下月 下周的 开始时间 结束时间

    <?php
    $now_time = time();
    $date=date("Y-m-d",$now_time);
    function get_date($date,$t='d',$n=0)
    {
        if($t=='d'){
           $firstday = date('Y-m-d 00:00:00',strtotime("$n day"));
           $lastday = date("Y-m-d 23:59:59",strtotime("$n day"));
        }elseif($t=='w'){
           if($n!=0){$date = date('Y-m-d',strtotime("$n week"));}
           $lastday = date("Y-m-d 00:00:00",strtotime("$date Sunday"));
           $firstday = date("Y-m-d 23:59:59",strtotime("$lastday -6 days"));
        }elseif($t=='m'){
           if($n!=0){$date = date('Y-m-d',strtotime("$n months"));}
           $firstday = date("Y-m-01 00:00:00",strtotime($date));
           $lastday = date("Y-m-d 23:59:59",strtotime("$firstday +1 month -1 day")); 
        }
        return array($firstday,$lastday);
    }
    $day1   = get_date($date,'d');
    $day2   = get_date($date,'d',-1);
    $week1 = get_date($date,'w');
    $week2 = get_date($date,'w',-1);
    $month1 = get_date($date,'m');
    $month2 = get_date($date,'m',-1);
    echo '<pre>';
    print_r($day1);//今天
    print_r($day2);//昨天
    print_r($week1);//这周
    print_r($week2);//上周
    print_r($month1);//这月
    print_r($month2);//上月
    echo '</pre>';
    

      

  • 相关阅读:
    Bean生命周期
    Bean的作用域
    神经网络训练中,傻傻分不清Epoch、Batch Size和迭代
    jQuery中选择器有哪几种
    数据库的事务机制
    多线程面试题
    HTTP请求报文和HTTP响应报文
    linux tomcat单机部署多应用
    flexbox预习
    作业
  • 原文地址:https://www.cnblogs.com/jthb/p/4489304.html
Copyright © 2011-2022 走看看