美文网首页
获取当月第一天和最后一天

获取当月第一天和最后一天

作者: zZ_d205 | 来源:发表于2020-12-11 16:01 被阅读0次
 getmonthDate() {
        var monthDate = {};
        var now = new Date(); //当前日期
        var nowMonth = now.getMonth(); //当前月
        var nowYear = now.getFullYear(); //当前年
        //本月的开始时间
        var monthStartDate = new Date(nowYear, nowMonth, 1);
        var yy = monthStartDate.getFullYear() + "-";
        var mm =
          (monthStartDate.getMonth() + 1 < 10
            ? "0" + (monthStartDate.getMonth() + 1)
            : monthStartDate.getMonth() + 1) + "-";
        var dd =
          monthStartDate.getDate() < 10
            ? "0" + monthStartDate.getDate()
            : monthStartDate.getDate();
        //本月的结束时间
        var monthEndDate = new Date(nowYear, nowMonth + 1, 0);
        var YY = monthEndDate.getFullYear() + "-";
        var MM =
          (monthEndDate.getMonth() + 1 < 10
            ? "0" + (monthEndDate.getMonth() + 1)
            : monthEndDate.getMonth() + 1) + "-";
        var DD =
          monthEndDate.getDate() < 10
            ? "0" + monthEndDate.getDate()
            : monthEndDate.getDate();
        monthDate.start_day = yy + mm + dd;
        monthDate.end_day = YY + MM + DD;
        return monthDate
        // this.params.start_day = yy + mm + dd; //本月的开始时间
        // this.params.end_day = YY + MM + DD; //本月的结束时间
      },

相关文章

网友评论

      本文标题:获取当月第一天和最后一天

      本文链接:https://www.haomeiwen.com/subject/addziktx.html