如何使用 moment.js 在 IE 中停止获取无效日期? [英] How can I stop getting an invalid date in IE with moment.js?
本文介绍了如何使用 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>
这篇关于如何使用 moment.js 在 IE 中停止获取无效日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文