antd DatePicker的使用

1.默認(rèn)時(shí)間

<DatePicker

? defaultValue={moment('20120203')}

? format={dateFormat}

/>

默認(rèn)當(dāng)前時(shí)間:

const dateFormat = 'YYYY-MM-DD';

<DatePicker

? defaultValue={moment()}

? format={dateFormat}

/>

moment()不帶參數(shù)表示默認(rèn)當(dāng)前日期

注意:

1. 獲取時(shí)間戳

獲取當(dāng)前時(shí)間戳:

moment().valueOf()

獲取固定時(shí)間的時(shí)間戳:

moment(date.format('YYYY-MM-DD')).valueOf()

date為moment格式

2. 獲取格式時(shí)間

moment().format('YYYY-MM-DD')

DatePicker組件獲取的時(shí)間都是moment格式的,要轉(zhuǎn)換一般用這兩種

時(shí)間戳轉(zhuǎn)成moment格式:

moment(時(shí)間戳)

2.不可選擇的日期

(1)只能選擇今天跟今天之后的日期:

? const disabledDate = (current) => {

? ? return current < moment().startOf('day');

? }

<DatePicker disabledDate={disabledDate}/>

(2)只能選擇今天之前的日期(不包括今天):

? const disabledDate = (current) => {

? ? return current > moment().startOf('day');

? }

<DatePicker disabledDate={disabledDate}/>

3.禁用日期框

<DatePicker disabled/>

4.日期區(qū)間范圍選擇

? <RangePicker defaultValue={[moment('20130607'), moment('20190301')]}/>

5.月份選擇

<MonthPicker defaultValue={moment()}/>

6.選擇周

<WeekPicker defaultValue={moment()}/>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容