moment设置当前月第一天,当前月最后一天

 例如:2021-7-1 至 2021-7-31

timeTime() {
// 开始时间
        let date = moment().startOf('month');   //当月第一天
        let y = date.get('year');
        let m = date.get('month') + 1;
        let d = date.get('date');
        this.startDateString = y + "-" + m + "-" + d;
//结束时间
        let date1 = moment().endOf('month');     //当月最后一天
        let yy = date1.get('year');
        let mm = date1.get('month') + 1;
        let dd = date1.get('date');
        this.endDateString = yy + "-" + mm + "-" + dd;
        
        this.setData({
            startDate: startDateString,
            endDate: endDateString,
        })
    },

你可能感兴趣的:(前端记录)