Home > Back-end >  How can I set choosen date as a default date in antd?
How can I set choosen date as a default date in antd?

Time:10-08

I want to set my choosen date as a default date in DatePicker antd.

<DatePicker
    allowClear={false}
    placeholder="Select date"
    onChange={this.changeDate}
    value={moment(this.props.choosenDate)}
/>

How can I do that?

value={moment(this.props.choosenDate) 

it doesn't work

CodePudding user response:

Here is an example from their documentation.

I think you should be using defaultValue

import { DatePicker, Space } from 'antd';
import moment from 'moment';

const dateFormat = 'YYYY/MM/DD';

...

<DatePicker defaultValue={moment('2015/01/01', dateFormat)} />

CodePudding user response:

You can use default value option.

<DatePicker
    defaultValue = {moment('2015/01/01', 'YYYY/MM/DD')}
    format = {'YYYY/MM/DD'}
/>

https://codesandbox.io/s/dv4mr?file=/index.js:241-251

CodePudding user response:

according to Moment Documents

let yourCustomDate = moment('24/12/2019 09:15:00', "DD MM YYYY hh:mm:ss");


<DatePicker
    allowClear={false}
    placeholder="Select date"
    onChange={this.changeDate}
    value={yourCustomDate}
/>
  • Related