Vue获取当前时间( 年初-年末、月初-月末、)

     // 获取年初-年末、月初-月末、
      getNowTime() {
        var now = new Date();
        var year = now.getFullYear(); //得到年份
        var month = now.getMonth(); //得到月份
        var day = now.getDate(); //得到天
        if (day < 10) {
          day = "0" + day
        }
        month = month + 1;
        month = month.toString().padStart(2, "0");
        var defaultDate = `${year}-${month}`;
        this.value1 = defaultDate;
        this.value2 = defaultDate;
        this.value3 = defaultDate;
        this.value4 = defaultDate;
        this.value6 = defaultDate;
        this.today.date_from = `${year}-${month}-${day}`
        this.today.date_to = `${year}-${month}-${day}`
        this.month.date_from = `${year}-${month}-01`
        this.month.date_to = `${year}-${month}-31`
        this.year.date_from = `${year}-01-01`
        this.year.date_to = `${year}-12-31`

        console.log(this.today.date_from + '-today.date_from')
        console.log(this.today.date_to + '-today.date_to')
        console.log(this.month.date_from + '-month.date_from')
        console.log(this.month.date_to + '-month.date_to')
        console.log(this.year.date_from + '-year.date_from')
        console.log(this.year.date_to + '-year.date_to')

        // 对象不要直接赋值,其中涉及深浅拷贝原理
        switch (this.top_value) {
          case 1:
            this.date = JSON.parse(JSON.stringify(this.today));
            break;
          case 2:
            this.date = JSON.parse(JSON.stringify(this.month));
            break;
          case 3:
            this.date = JSON.parse(JSON.stringify(this.year));
            break;
          case 4:
            this.date.date_from = null;
            this.date.date_to = null
            break;

          default:
            break;
        }
      },

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值