SoFunction
Updated on 2025-04-04

Ant Design moment object and string mutual conversion tutorial

moment object to string

=('YYYY-MM-DD');

String to moment object

=moment();

Supplementary knowledge:vue ant design date component range-picker form

This is the official document

parameter illustrate type
Set the default time, minute, and second when the user selects a date moment[]

Which datepicker assignment for ordinary tickets has been performed before?

The difference is that range-picker saves two dates into an array of type moment[]

This is quite fucking. The background doesn't want to split it into 2 fields, so it has to convert it into a string

= (',')

However, it is not OK to take it back and convert it into an array to assign values...

I have been looking for the specific reasons for a long time before I can compare them. I won’t talk about the reasons anymore, let’s take a look at the correct process.

= [ [0].toISOString() , [1].toISOString() ];

= (',')

Then the assignment is the normal assignment:

?= [moment([0], 'YYYY-MM-DD HH:mm:ss'), moment([1], 'YYYY-MM-DD HH:mm:ss')]:null
({ showDate:  ?  : null })

The above tutorial on the mutual conversion between Ant Design moment object and string is all the content I share with you. I hope you can give you a reference and I hope you can support me more.