zoukankan      html  css  js  c++  java
  • php 获取某个月的周次信息

    通过年,月份获取一个月的周次信息

    如果本月头一天不是星期一,则向上一个月取周一,本月最后的几天如果不能正好是一周,则忽略。

    例如

    2019-09月计算出来的结果

    2016-08-29---2016-09-04
    2016-09-05---2016-09-11
    2016-09-12---2016-09-18
    2016-09-19---2016-09-25

      

    /*传入年份($current_year)和月份($current_month)*/
    //获取某年某月的周次信息
    public static function getWeekData($current_year, $current_month)
    {
    $weekData = [];
    $firstday = strtotime($current_year . '-' . $current_month . '-01');
    $monday = $firstday - 86400 * (date('N', $firstday) - 1);//计算第一个周一的日期
    for ($i = 1; $i <= 5; $i++) {
    $start = date("Y-m-d", $monday + ($i - 1) * 86400 * 7);//起始周一
    $end = date("Y-m-d", $monday + $i * 86399 * 7);//结束周日
    if (date('m', $monday + $i * 86399 * 7) != $current_month) {
    continue;
    }
    $data = [$start, $end];
    array_push($weekData, $data);
    }
    return $weekData;
    }
  • 相关阅读:
    HDU 2544 (Djikstra)
    HDU 1237(表达式求值)
    HDU1690 (Floyd)
    《大道至简》读后感
    第6周总结
    第8周总结
    第7周总结
    第四周总结
    第5周总结
    java程序
  • 原文地址:https://www.cnblogs.com/T8888/p/15668634.html
Copyright © 2011-2022 走看看