Angular Date Filter not working in firefox

I use a date filter to format my date in an angular application.

In Firefox, I get the date value as

undefined NaN, NaN NaN: NaN: NaN PM

In Chrome, it works great like

June 25, 2014 7:22:47 a.m.

My code is as follows.

var formatDate = new Date(info.list[i].date);
var newDate=$filter('date')(formatDate, 'medium');

How to make it work in Firefox?

+3
source share
2 answers

I ran into this problem and found that the problem is that Chrome / Opera and Firefox / Safari have different tolerances for creating a new Date Javascript 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")

Date, AngularJS , .

+8

moment.js, -.

NaN firefox,

var myDate = Date.parse(date);

. :

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

.

+2

All Articles