Angular Date filter is not workig in firefox

旧时模样 提交于 2019-12-05 12:07:40

I ran into this issue and found that the problem was Chrome/Opera and Firefox/Safari have different tolerances for creating a new Javascript Date object.

This works in Chrome and Opera, but not Firefox and Safari:

var myDate = new Date("2014-08-12 11:46:26.509")

This works in all mentioned browsers:

var myDate = new Date("2014-08-12T11:46:26.509")

Once I had a proper Date object created, the AngularJS date filter works as expected.

There is a moment.js library that facilitates dates parsing and that works cross-browser.

I also had a problem with NaNs in firefox and I was using

var myDate = Date.parse(date);

for Date creation. Switched to:

var myDate = moment(date).toDate();

and everything works flawlessly.

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