To format a string "05.11.2022" into date "11/5/2022" in moment.js library, you can use the following code:
index.tsx160 chars4 lines
In the code above, moment()
function is used to parse the input string dateString
with format "DD.MM.YYYY"
. Then, format()
method is used to format the date according to the desired format "MM/DD/YYYY"
.
Note that this method is not deprecated and will work with moment.js version 2.0+.
Also, keep in mind that in the US, dates are often written in the format "MM/DD/YYYY", while in other countries, like the UK and Australia, the format "DD/MM/YYYY" is more common. So, make sure to adjust the format string accordingly to fit your region's convention.
gistlibby LogSnag