Reputation: 1477
Using AntDesign datepicker to build a project.
<DatePicker
value={moment(item.remarkValue)}
format="YYYY-MM-DD HH:mm:ss"
showTime={{ defaultValue: moment('00:00:00', 'HH:mm:ss') }}
showTime={{ format: 'YYYY-MM-DD HH:mm:ss' }}
placeholder="请选择生效日期"
/>
I found that i can select the time and save it. But when I refresh the page and querying the server, got the data from server, the item.value
is 2019-12-05 08:04:00
but the DatePicker
shows empty like this:
So, how can i load the date string with format (YYYY-MM-DD HH:mm:ss) with antd DatePicker?
Upvotes: 2
Views: 2211
Reputation: 61
It even seems that after giving a value attribute to DatePicker, the user is unable to reselect a new date and time. So, a feasible solution would be.
defaultValue={item.remarkValue?moment(item.remarkValue,"YYYY-MM-DD HH:mm:ss"):null}
You could try here for yourself.
Upvotes: 2
Reputation: 355
It seems below code gives invalid moment object as there is no proper format provided in moment() and this datetime string is not recognized by moment itself.
value={moment(item.remarkValue)}
Try below code
value={item.remarkValue?moment(item.remarkValue,"YYYY-MM-DD HH:mm:ss"):null}
Upvotes: 2