Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moment returning an invalid date while using Hermes JS Engine

When I was using jsc Engine, everything was working fine but when I shifted from jsc engine to Hermes Engine in my react native app I started getting Invalid date where I was using moment.

CODE:

const defaultDate = moment(currentTimeStamp).format("YYYY/MM/DD"); //till this it works fine
return moment(defaultDate).toDate().getTime(); // throws INVALID DATE
like image 248
sakshya73 Avatar asked Dec 11 '25 23:12

sakshya73


1 Answers

After some R&D, I was able to figure out the issue myself so I thought to share it here.

Solution 1 :

Instead of using format like format("YYYY/MM/DD");. Use it like format("YYYY-MM-DD"); as this is one of the standard format that moment understands.

Solution 2:

If you need that format only(which was my case). You need to tell the moment the format that you are using. Like this:

return moment(defaultDate,"YYYY/MM/DD").toDate().getTime();
like image 117
sakshya73 Avatar answered Dec 15 '25 19:12

sakshya73



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!