• js 获取某年的某天是第几周


    /**
    2 * 判断年份是否为润年
    3 *
    4 * @param {Number} year
    */
    6 function isLeapYear(year) {
    7     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
    8 }
    9 /**
    10 * 获取某一年份的某一月份的天数
    11 *
    12 * @param {Number} year
    13 * @param {Number} month
    14  */
    15 function getMonthDays(year, month) {
    16     return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] || (isLeapYear(year) ? 29 : 28);
    17 }26 /**
    27 * 获取某年的某天是第几周
    28 * @param {Number} y
    29 * @param {Number} m
    30 * @param {Number} d
    31 * @returns {Number}
    32  */
    33 function getWeekNumber(y, m, d) {
    34     var now = new Date(y, m - 1, d),
    35         year = now.getFullYear(),
    36         month = now.getMonth(),
    37         days = now.getDate();
    38     //那一天是那一年中的第多少天
    39     for (var i = 0; i < month; i++) {
    40         days += getMonthDays(year, i);
    41     }
    42
    43     //那一年第一天是星期几
    44     var yearFirstDay = new Date(year, 0, 1).getDay() || 7;
    45
    46     var week = null;
    47     if (yearFirstDay == 1) {
    48         week = Math.ceil(days / yearFirstDay);
    49     } else {
    50         days -= (7 - yearFirstDay + 1);
    51         week = Math.ceil(days / 7) + 1;
    52     }
    53
    54     return week;
    55 }

  • 相关阅读:
    k8s 基础 pod操作
    python 字典 get 小例子
    linux 日志
    python 基础 文件操作
    k8s 基础 k8s架构和组件
    k8s 基础 核心概念
    HDU1272--小希的迷宫(并查集)
    POJ1182--食物链(经典并查集)并查集看不出来系列2
    HDU 3038 How Many Answers Are Wrong (并查集)---并查集看不出来系列-1
    二分快速幂
  • 原文地址:https://www.cnblogs.com/SZ2015/p/4629817.html
Copyright © 2020-2023  润新知