Question

In JSON I receive a epoch timestamp which I'm trying to convert correctly

var d = new Date(1398693600000);
  • Chrome, Firefox etc = Mon Apr 28 2014 15:00:00 GMT+0100 (BST)
  • IE8 = Mon Apr 28 07:00:00 PDT 2014

So straight away it's on a different timezone. Not helpful.

Using MomentJS

moment(d).format();
  • Chrome: 2014-04-28T15:00:00+01:00
  • IE8: 2014-04-28T07:00:00-07:00

moment.utc(d).format();

  • Chrome: 2014-04-28T14:00:00+00:00
  • IE8: 2014-04-28T14:00:00+00:00

So using UTC gets consistent time across browsers, but it's an hour out. Bear in mind I'm on GMT so that will effect things down the line.

Is it a problem with MomentJS?

So, what do I need to do to sort IE8? :) I've no doubt the answer is staring me straight in the face.

Cheers

Was it helpful?

Solution

The two dates are the same, just the string representation is different. For instance, these are all the same exact time:

new Date('Mon Apr 28 2014 15:00:00 GMT+0100 (BST)');
new Date('Mon Apr 28 07:00:00 PDT 2014');
new Date('2014-04-28T14:00:00+00:00');
new Date('Mon Apr 28 2014 10:00:00 GMT-0400 (EDT)');

So any calculations and displays should come out correctly. Now, why you are seeing a different timezone seems strange since, AFAIK, every browser simply uses your system clock.

However, you've commented that you're using a virtual machine to test IE. It is quite likely that that VM has a different timezone set and that's why you are seeing a different text representation in IE.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top