js获取当前日期的前30天日期数组

// 获取当前日期前30天的日期数组
  get_30_day = () => {
    var thrityMonth = [];
    for (var i = 0; i < 30; i++) {
      thrityMonth.unshift(new Date(new Date().setDate(new Date().getDate() - i)).toLocaleDateString())
    }
    console.log('thrityMonth====>', thrityMonth)
  }
// 获取当前日期前30天的日期数组 只取每一天的当月第几天,例如2020-11-27 中的27
  get_30_day = () => {
    var thrityDay = [];
    for (var i = 0; i < 30; i++) {
      let currDate = new Date(new Date().setDate(new Date().getDate() - i)).toLocaleDateString();
      currDate = currDate.includes('/') ? currDate.replaceAll('/', '-') : currDate;
      let currDay = currDate.split('-')[currDate.split('-').length - 1];
      thrityDay.unshift({ date: currDay, score: i });
    }
    this.setState({ dataList: thrityDay });
    console.log('LDate====>', thrityDay)
  }

 


版权声明:本文为hzxOnlineOk原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。