简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM