2

following example try to parse date from string (2016-03-27T02:00:00) using moment.js

http://jsfiddle.net/PAc3j/507/

var date = moment("2016-03-27T02:00:00").format('DD-MM-YYYY hh:mm:ss');
alert(date);

Script executed on firefox gives 2016-03-27 01:00:00

Script executed on chrome gives 2016-03-27 03:00:00

How to enforce moment to return the same date regardless of used browser?

I forgot to mention the context. String passed to moment constructor is user localtime. The date is special because in Europe at this time TimeZone is changed from UTC+1 to UTC+2. So in local time 2016-03-27 02:00:00 does not exists. Browser have to fallback to existing local date. I would like this date to be the same regardless of browser.

Marek
  • 81
  • 1
  • 4

1 Answers1

1

It seems a timezone issue. Have you tried to set the utc timezone?

Right from Moment docs :

If you wish to interact with the date as a UTC date, use moment.utc

moment.utc('2016-01-01T23:35:01');

This results in a date with a utc offset of +0:00

Or you could create the date fixing your timezone, if it's different from utc, like :

var date = moment("2016-03-27T02:00:00+02:00").format('DD-MM-YYYY hh:mm:ss');
Rajesh
  • 24,354
  • 5
  • 48
  • 79
Ketty D.S.
  • 19
  • 4