zoukankan      html  css  js  c++  java
  • 获取两个时间节点的月份列表&&每个月份的开始时间及结束时间

    //Q:从今天起之前五个月的列表
    date_default_timezone_set('PRC');
    $time=strtotime('-5 month'); //包含本月
    $begin = strtotime(date('Y-m-01 00:00:00', $time));
    $end = strtotime(date('Y-m-01 00:00:00') . ' +1 month -1 day');
    if ($begin > $end) {
        die('开始时间不能大于结束时间!');
    }
    $motharr = array();
    $format_month= array();
    
    do{
        $motharr[] = date('Y-m', $begin);
        /* 获取月份间的开始结束时间 */
        $format_begin=date('Y-m-01 00:00:00', $begin);
        $format_end = date('Y-m-d 59:59:59',strtotime($format_begin.' +1 month -1 day'));
        $dtmp['fbegin'] = $format_begin;
        $dtmp['fend'] = $format_end;
        $format_month[]=$dtmp;
    }while(($begin = strtotime('+1 month', $begin)) <= $end);
    //$motharr[] = date('Y-m', ($begin));
    //while (($begin = strtotime('+1 month', $begin)) <= $end) {
    //    $motharr[] = date('Y-m', $begin);
    //    /* 获取月份间的开始结束时间 */
    //    $format_begin=date('Y-m-01 00:00:00', $begin);
    //    $format_end = date('Y-m-d 59:59:59',strtotime($format_begin.' +1 month -1 day'));
    //    $dtmp['fbegin'] = $format_begin;
    //    $dtmp['fend'] = $format_end;
    //    $format_month[]=$dtmp;
    //}
    arsort($motharr);   // 时间排序
    print_r($motharr);
    print_r($format_month);
    die;
  • 相关阅读:
    CCF-CSP题解 201509-4 高速公路
    CCF-CSP题解 201403-4 无线网络
    CCF-CSP题解 201512-4 送货
    2019年9月10日
    53. 最大子序和
    54. 螺旋矩阵
    59. 螺旋矩阵 II
    61. 旋转链表
    62. 不同路径
    70. 爬楼梯
  • 原文地址:https://www.cnblogs.com/sien6/p/7207058.html
Copyright © 2011-2022 走看看