0

I'm getting different results when calling new Date() on different tabs in my browser. On one tab, I have a web application running on a remote server and I executed "new Date()" and I received:

Fri Sep 21 2018 15:20:16 GMT-0700 (GMT-07:00)

which is what I want. On a different tab, I have the same application running locally and I run "new Date()", but I receive

Fri Sep 21 2018 22:20:16 GMT+0000 (GMT)

Why is the timezones listed differently? Both the server and my local machine are in the same time zone.

Scott Chantry
  • 1,115
  • 5
  • 16
  • 29
  • Possible duplicate of [javascript Date timezone issue](https://stackoverflow.com/questions/29174810/javascript-date-timezone-issue) – Tibrogargan Sep 21 '18 at 22:34
  • 1
    The geographic location is irrelevant, it's the timezone setting of the system that matters. Both timestamps represent the same moment in time, but the systems appear to be set to different timezones. – RobG Sep 22 '18 at 03:19
  • I'm running the same command in the same browser on the same computer, how can one browser tab have a different timezone than the tab right next to it? – Scott Chantry Sep 22 '18 at 13:58

1 Answers1

0

As per mdn docs

If no arguments are provided, the constructor creates a JavaScript Date object for the current date and time according to system settings for timezone offset.

I think timezone offset is different on local and other machine that you have. Check with following function. date.getTimeZoneOffset()

Try using UTC date format.

Shubham Gupta
  • 2,596
  • 1
  • 8
  • 19