Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

moment.js from now is reporting different results in firefox/ie then chrome

Tags:

momentjs

We and foolishly assumed a block of momentjs code would work in all browsers. Right now its correctly working in chrome, but all other browsers its not applying the UTC offset. How do I make this code work consistently in other browsers? Right now chrome is working, all others are not.

 new moment(new Date(date)).fromNow();
 //below shows an example of an exact date. 
 var now = new moment(new Date("2013-09-30T23:33:36.937")).fromNow();

In chrome you would see something like "now", all other browsers you would see "in 4 hours"

like image 452
Nix Avatar asked Oct 17 '25 14:10

Nix


1 Answers

The way to get it to work:

var now = moment.utc("2013-10-01T13:15:30.937").fromNow();

Note that if you turn it into a "Date" and call moment.utc

var now = moment.utc(new Date("2013-10-01T13:15:30.937")).fromNow();

It will not work. It makes sense now that I think of it.

like image 186
Nix Avatar answered Oct 21 '25 08:10

Nix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!