I am using date filter to format my date in my angular application.
In Firefox, I'm getting the date value as
undefined NaN, NaN NaN:NaN:NaN PM
In Chrome its works perfectly as
Jun 25, 2014 7:22:47 AM
My code is as follows.
var formatDate = new Date(info.list[i].date);
var newDate=$filter('date')(formatDate, 'medium');
How do I get it to work in Firefox?
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 NaN
s 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With