如何使用 moment.js 在 IE 中停止获取无效日期?
问题描述:
这总是返回无效日期".它适用于 Chrome 和 Safari,但在 IE 中我总是得到一个无效的日期.
This always returns "invalid date". It works in Chrome and Safari, but in IE I always get an invalid date.
有问题的代码:
var utcMoment = moment.utc(value.Timestamp);
value.Timestamp
采用以下格式:17 Sep 15 19:55:37"
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.
答
您可以在创建时刻时明确定义格式.
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>