AlexZ33 / lessions

自己练习的各种demo和课程
12 stars 2 forks source link

时间函数封装 #27

Open AlexZ33 opened 5 years ago

AlexZ33 commented 5 years ago

/**
 * 获取当前月份的天数
 * @param year {number} 年
 * @param month {number} 月
 * @return {number} 天数
 */
function getDay (year, month) {
  if (!year || !month) {
    return 0;
  } else if (/^(1|3|5|7|8|10|12)$/.test(month)) {
    return 31;
  } else if (/^(4|6|9|11)$/.test(month)) {
    return 30;
  } else if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
    return 29;
  } else return 28;
}