I’m using Moment.js to parse the Date
from a string
, however every time I parse it I have to specify the format the string is in, but my string can either be dd-MM-yy
or d/m/yyyy
or d-MM-yyyy,
its always changing, so writing out all the different formats will be challenging, is there a way to parse it if I know the string will always be the day followed by the month followed by the year? Either with JavaScripts date constructor or a third party library like Moment.js
Question posted in Javascript
A very good W3school tutorial can be found here.
A very good W3school tutorial can be found here.
3
Answers
Can you share your code, I didnt exactly get it but while I was using moment.js
and I had date of any kind , we can format is by using
If that clears your doubt then well and good otherwise let me know what have you sent and what exactly is required in code. Thanks
read this example code
Simply match for numbers (i.e. days, month, year), then use the
Date()
constructor: