Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date-fns parseISO returning wrong date

Hello I am getting wrong dates from Date-fns. I am formatting new Date() with date-fns format.

format(date, "yyyy-MM-dd")

So when I console.log, this happens

console.log("dateOfBirth ", dateOfBirth); //  1997-04-06
console.log("parsedDate ", parseISO(dateOfBirth));  // 1997-04-05T18:00:00.000Z

Why are the two dates different? So what's happening here?

like image 513
Pranta Avatar asked Dec 28 '25 19:12

Pranta


1 Answers

I think it is just a timezone issue, try to append "T00:00" when you create your date object, when you don't specifies the hours, it depends on which timezone user is. Probably you are in UTC - 6, right?
const dateOfBirth = new Date("1997-04-06T00:00")

like image 183
Adriano Machado Avatar answered Dec 30 '25 11:12

Adriano Machado



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!