mpora
mpora

Reputation: 1479

moment.js returning wrong day for a date

I have a field with a value of 03-01-2020 as a date in DD-MM-YYYY date format. When I use

moment.utc(document.getElementById('date').value, "DD-MM-YYYY HH:mm:ss").toDate()

and the value turns out to be a day behind as shown below:

Thu Jan 02 2020 17:00:00 GMT-0700 (Mountain Standard Time)

Is there anything I am doing wrong?

Upvotes: 0

Views: 2221

Answers (1)

mpora
mpora

Reputation: 1479

Changed the line to the following:

moment(document.getElementById('date').value + " 12:00", "DD-MM-YYYY HH:mm:ss").utc().format("YYYY-MM-DD HH:mm")

Based of this answer: moment.js - UTC gives wrong date

Upvotes: 0

Related Questions