根据月份获取当前月份天数

 setTitle() {
      let date = '';
      if (this.dialogStatus != 'create') {
        date = this.rowData.period;
      } else {
        date = this.dialogInfo.settlementDate;
      }
      date = date.split('-');//获取到的当前的月份
      let year_ = date[0];
      let day_ = date[1];
      let day_zero = date[1];
      if (_.startsWith(day_, 0)) {
        day_ = day_.substring(1);
      }
      date[1] = year_;
      this.monthTitle = day_;
      this.yearTitle = year_ ;
      // 处理结算日期

	 这部分代码是处理日期的代码
      let runYear = isRunYear(this.yearTitle); 
      let num1 = ['01','03','05','07','08','10','12'];//31天
      let num2 = ['04','06','09','11'];//30天、
      判断当前月份是满足31天还是30天,2月份需要单独 处理
      if (_.includes(num1, day_zero)){
        this.dayNumEnd = '31';
      }else if (_.includes(num2, day_zero)){
        this.dayNumEnd = '30';
      }else {
        // 2月处理平年闰年
        if (runYear){
          this.dayNumEnd = '29';
        }else {
          this.dayNumEnd = '28';
        }
      }
      this.beginDate = `${this.yearTitle}-${day_zero}-01`;
      this.endDate = `${this.yearTitle}-${day_zero}-${this.dayNumEnd}`;
    },

// 判断闰年的函数
export function isRunYear(year) {
  // 条件:能被4整除并且不能被100整除,或者被400整除的
  var flag = false;
  if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
    flag = true;
  }
  return flag;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值