简体   繁体   English

safari 和 FF 中的 moment.js 无效日期

[英]moment.js invalid date in safari and FF

I have the following date: 06-24-2016 02:18:13 PM我有以下日期:06-24-2016 02:18:13 PM

I'm trying to use moment.js but getting invalid date in Safari and FF using the following:我正在尝试使用 moment.js 但使用以下方法在 Safari 和 FF 中获取无效日期:

moment(data.d.results[0].Updated_On).format('MMMM Do YYYY'))

Not sure what I need to do to get it working an all browsers?不确定我需要做什么才能让它在所有浏览器上运行?

just provide the correct format for your date, then it will work everywhere 只需提供正确的日期格式,便可以在任何地方使用

var d = "06-24-2016 02:18:13 PM";
alert(moment(d, "MM-DD-YYYY HH:mm:ss A").format("MMMM Do YYYY"))

可能不是推荐的方式。但这对所有浏览器都适用:

moment(data.d.results[0].Updated_On, "MM-Do-YYYY").format('MMMM Do YYYY'))

Probably not applicable to most.可能不适用于大多数人。 But in my case I was appending 'z' to my date string.但就我而言,我将“z”附加到我的日期字符串中。 Which worked fine in Chrome but failed testing in Safari. Simply change the 'z' to a capitalized 'Z' fixed for me.在 Chrome 中运行良好,但在 Safari 中测试失败。只需将 'z' 更改为大写的 'Z' 即可。

Thought I'd share this rare edge case.以为我会分享这个罕见的边缘案例。

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

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