zoukankan      html  css  js  c++  java
  • 【react+ts+antd】DatePicker日期选择器不能选择过去的时间(===当前时间之前的时间)

    组件:

    {form.getFieldValue('status') === '03' &&
                        getFieldDecorator('timingPublishTime', {
                            initialValue:
                                isEdit && infomentDetail.timingPublishTime
                                    ? moment(infomentDetail.timingPublishTime)
                                    : moment(),
                            rules: [{ required: true, message: '请选择定时发布时间' }]
                        })(
                            <DatePicker
                                format="YYYY-MM-DD HH:mm:ss"
                                disabledDate={disabledDate}
                                showTime
                                disabledTime={disabledTime}
                            />
                        )}
    

      

    方法:

    const range = (start: any, end: any) => {
            const result = [];
            for (let i = start; i < end; i += 1) {
                result.push(i);
            }
            return result;
        };
        // 不可选择以前的时间
        const disabledDate = (currentDate: any) => currentDate && currentDate < moment();
        const disabledTime = (date: any) => {
            const hours = moment().hours();
            const minutes = moment().minutes();
            const seconds = moment().seconds();
            // 当日只能选择当前时间之后的时间点
            if (date && moment(date).date() === moment().date()) {
                return {
                    disabledHours: () => range(0, 24).splice(0, hours),
                    disabledMinutes: () => range(0, 60).splice(0, minutes + 1),
                    disabledSeconds: () => range(0, 60).splice(0, seconds + 1)
                };
            }
            return {
                disabledHours: () => [],
                disabledMinutes: () => [],
                disabledSeconds: () => []
            };
        };
    

      

  • 相关阅读:
    intelliJ idea 9设置
    Ibatis的cache使用
    发现个漂亮的eclipse插件
    Java compiler level does not match the version of the installed Java project facet
    ajax servlet端小问题
    Annotation学习小结
    杯具的webservice,杯具的axis和xfire
    idea 9
    aptana 注释快捷键失效
    javascript深入理解js闭包
  • 原文地址:https://www.cnblogs.com/nangras/p/14119367.html
Copyright © 2011-2022 走看看