parsing DD/MM/YYYY format returns Invalid Date
parse('23/03/2018')
Version: 1.30.1
Unfortunately, it's not a valid date string. JavaScript (as well as date-fns) accepts ISO 8601 (and some other formats like RFC 5322 but it depends on the engine/browser implementation):
new Date('23/03/2018')
//=> Invalid Date
new Date('2018/03/23')
//=> Fri Mar 23 2018 00:00:00 GMT+0530 (India Standard Time)
In v2 we've introduced parse function that can help you digest the string, but the easiest solution is to use this function that I wrote just for you:
function parse(str) {
const [date, month, year] = str.split('/').map(n => parseInt(n))
return new Date(year, month - 1, date)
}
parse('23/03/2018')
//=> Fri Mar 23 2018 00:00:00 GMT+0530 (India Standard Time)
@kossnocorp The worldwide most common order style is day, month, year accoring to Wikipedia. How can it not be supported?
In my opinion there should be an option to tell the parse function which format to use:
e.g. 01.02.2019 could be 1st of february or 2nd of janaury but only in the US.
Btw. in your example you wrote date, month, year but didn't you mean day, month, year?
Most helpful comment
@kossnocorp The worldwide most common order style is day, month, year accoring to Wikipedia. How can it not be supported?
In my opinion there should be an option to tell the parse function which format to use:
e.g.
01.02.2019could be1st of februaryor2nd of janaurybut only in the US.Btw. in your example you wrote
date, month, yearbut didn't you meanday, month, year?