I have very irregular date formats, like the following:
["December 15th", "October 31st", "31 of October", "November 25th 2022", "22.10.2022", "15 November 2022", "9th of April 2023", "Friday 25 November 2022"]
I would like to format them to MM/DD/YYY, or another format that could then be formatted to a standard format.
I was hoping to get ideas about the best way of doing this in Javascript / Nodejs.
I'm also open to using an 3rd party API / train a ML model, or anything else.
Thanks.
I've tried the following:
- cleanup step (remove ',', '.')
- parsing with Date.parse()
- creating a new Date() by feeding it the output of Date.parse()
ex:
let cleaned = "9th of April".replace("th", "").replace("of", "") // returns '9 april 2023'
let timestamp = Date.parse(cleaned);
let date = new Date(timestamp);
console.log(date);
Which is fine in this case, but not general purpose enough.