0
点赞
收藏
分享

微信扫一扫

js判断年份是否为闰年及当月月数所带天数

ixiaoyang8 2022-02-18 阅读 54

闰年能被4整除且不能被100整除,或能被400整除。

img

img

简单代码

function year(){
  if(year%4 == 0 && year%100 != 0 || year%400 == 0){
         console.log('闰年');
  }else{
    console.log('平年');
  }
}

局部代码

  created() {
    let shippingCompanyId = this.$route.params.shippingCompanyId
    let month = this.$route.params.month
    // console.log('路由1',this.$cloneDeep(this.$route.params))
    if(month && month != undefined){
      let strYear= this.$route.params.month.substring(0,4)
      let submonth = month.substr(month.lastIndexOf("-") + 1,4);  //截取最后一个点号后4个字符
      this.tempSearch.startTime = month + '-01 00:00:00'
      // **************************
      if(['01','03','05','07','08','10','12'].includes(submonth)){
        this.tempSearch.endTime = month + '-31 23:59:59'
      }else if(['02'].includes(submonth)){
        if(strYear%4==0 && strYear%100!=0 || strYear%400==0){ // 闰年 闰年能被4整除且不能被100整除,或能被400整除。
          this.tempSearch.endTime = month + '-29 23:59:59'
        }else{ // 平年
          this.tempSearch.endTime = month + '-28 23:59:59'
        }
      }else{
        this.tempSearch.endTime = month + '-30 23:59:59'
      }
      // **************************
    }
    if(shippingCompanyId){
      this.args.search.shippingCompanyId = shippingCompanyId
      this.getList() // 获取列表
    }else{
      this.getList() // 获取列表
    }
  },
举报

相关推荐

0 条评论