js 某一天之前四个季度的最后一天

 //可选择当前服务器时间往前的四个季度的最后一天
            getMonthLastDay() {
                getCurrentTime().then(({ data })=>{
                    let today = data
                    today = new Date(today); //获取当前时间
                    const month = today.getMonth() + 1;//getMonth返回0-11
                    let year = today.getFullYear();
                    let lastDay = {};

                    if (month >= 1 && month <= 3) {//去年的四个季度
                        lastDay.first = this.getLastDay( year-1 , 3)
                        lastDay.sec = this.getLastDay( year-1 , 6)
                        lastDay.thi = this.getLastDay( year-1 , 9)
                        lastDay.for = this.getLastDay( year-1 , 12)
                    } else if (month >= 4 && month <= 6) {//去年的三个今年第一季度
                        lastDay.first = this.getLastDay( year-1 , 6)
                        lastDay.sec = this.getLastDay( year-1 , 9)
                        lastDay.thi = this.getLastDay( year-1 , 12)
                        lastDay.for = this.getLastDay( year , 3)
                    } else if (month >= 7 && month <= 9) {//去年的两个今年第一,二季度
                        lastDay.first = this.getLastDay( year-1 , 9)
                        lastDay.sec = this.getLastDay( year-1 , 12)
                        lastDay.thi = this.getLastDay( year , 3)
                        lastDay.for = this.getLastDay( year , 6)
                    } else {//去年的3个今年第一,二,三季度
                        lastDay.first = this.getLastDay( year-1 , 12)
                        lastDay.sec = this.getLastDay( year , 3)
                        lastDay.thi = this.getLastDay( year , 6)
                        lastDay.for = this.getLastDay( year , 9)
                    }
                    this.lastDay = Object.values(lastDay);
                });
            },
            //输入年月 获取月份最后一天
            getLastDay(y,m){
                let dt = new Date(y,m,1);
                dt = new Date(dt.getTime()-1000*60*60*24);
                return dt.getFullYear().toString() + "-" + (dt.getMonth()+1).toString() + "-" + dt.getDate().toString()
            }
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值