简体   繁体   English

moment.js 返回错误的日期日期

[英]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.我有一个值为03-01-2020的字段作为 DD-MM-YYYY 日期格式的日期。 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基于这个答案: moment.js - UTC 给出错误的日期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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