문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top