主要要清楚setDate()和new Date()的参数
0表示上个月的最后一天,

    getCurrentMonthTime(){
      const date = new Date();
      // 设置为日期1号
      date.setDate(1);
      // 获取当前月份(date.getMonth()返回的是0-11)
      let month = parseInt(date.getMonth() + 1);
      // 获取当月第一天日期
      let startDay = date.getDate();
      // 获取当前月的最后一天。参数0代表上个月的最后一天
      const endOfMonth = new Date(date.getFullYear(), month, 0).getDate();
      // 设置日期为当前月的最后一天
      date.setDate(endOfMonth);
      // 获取当月最后一天日期
      let endDay = date.getDate();
      if (month < 10)  month = '0' + month
      if (startDay < 10)  startDay = '0' + startDay
      if (endDay < 10)  endDay = '0' + endDay
      const startTime = date.getFullYear() + '-' + month + '-' + startDay + " " + "08:00:00";
      const endTime = date.getFullYear() + '-' + month + '-' + endDay + " " + "08:00:00";
      return [startTime,endTime]
    },
Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐