How can I stop getting an invalid date in IE with moment.js?

喜欢而已 提交于 2021-01-29 02:04:55

问题


This always returns "invalid date". It works in Chrome and Safari, but in IE I always get an invalid date.

The code in question:

  var utcMoment = moment.utc(value.Timestamp);

value.Timestamp is in this format: "17 Sep 15 19:55:37"

Should I be using a different date format? I am unsure how to proceed.


回答1:


You can explicitly define the format when creating the moment.

var utcMoment = moment.utc("17 Sep 15 19:55:37", "DD MMM YY HH:mm:ss");
console.log(utcMoment);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js"></script>


来源:https://stackoverflow.com/questions/32660040/how-can-i-stop-getting-an-invalid-date-in-ie-with-moment-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!