I am getting dates from an API in one of these formats "mm-dd-yyyy"
or "mm/dd/yyyy"
also these are in string and I want to parse them from string to js date object
so when I do new Date('12/07/2021')
or new Date('12-07-2021')
I get the output date which has one day previous 2021-12-06T18:30:00:000Z
.
But if I pass the date in yyyy-mm-dd
format like this new Date('2021-12-07')
then I get correct date as output 2021-12-07T00:00:00.000Z
I am facing this issue in the backend with node js.
possible solution according to me is converting the string from mm-dd-yyyy
to yyyy-mm-dd
format. But how do I do this ?
NOTE: : I cant use moment js as this is a new project and due to moment js depreciation