Requirement: Select the time interval, and can only select the time before the current moment, and the minutes and seconds should also be limited. (For example, if it is 2021-06-21 16:35:30, you can only select the time before this moment, which has not yet happened.) The expectation graph is as follows

Moment import moment from ‘moment’

2, time control set date and time disable

 <a-range-picker style="width: calc(100% - 100px);"  :show-time="{ format: 'HH:mm:ss' }"
                            :disabled-date="disabledDate"
                            :disabled-time="disabledDateTime"

                            format="YYYY-MM-DD HH:mm:ss" @ok="onOk" />
Copy the code

3. Specific implementation functions:

// Set the date unavailable after today
disabledDate(current) {
        // Can not select days after today and today
        return current && (current >= moment().endOf('day');
      },
Copy the code
DisabledDateTime (dates,partial) {// Let nowHours = moment().hours(); //0~23 let nowMinutes = moment().minutes(); //0~59 let nowSeconds = moment().seconds(); //0~59 if (dates&&moment(dates[1]).date() === moment().date()&&partial=='end') { return { disabledHours: () => this.range(0,nowHours), disabledMinutes: () => ((moment(dates[1]).hour() === moment().hour())? this.range(0,nowMinutes):[]), disabledSeconds: () => ((moment(dates[1]).hour() === moment().hour())&&(moment(dates[1]).minutes() === moment().minutes())? this.range(0,nowSeconds):[]), }; }}Copy the code
range(start, end) {
        const result = [];
        for (let i = start; i < end; i++) {
          result.push(i);
        }
        return result;
      },
Copy the code