-2

I have below code in my function

alert(date);
var result = new Date(date);      
alert(result);

Output as below

When I set my system time as India

2017-11-07
Tue Nov 07 2017 05:30:00 GMT+0530 (India Standard Time)

When I set my System timezone as US & Canada

2017-11-07
Mon Nov 06 2017 18:00:00 GMT-0600 (Central Standard Time)

What is the issue here and how can I fix this?

vamsi
  • 1,488
  • 3
  • 28
  • 66
  • 1
    _“What is the issue here”_ - you tell us ... what issue do you have with this? Of course it can happen that you get a different day, if you switch to a different time zone ... – CBroe Sep 05 '17 at 08:24
  • 2
    This is working exactly as it's supposed to work. – Cerbrus Sep 05 '17 at 08:24
  • If you change your System's time, obviously your browser's JS engine will take that. There is nothing wrong. – Om Sao Sep 05 '17 at 08:25
  • 1
    Check this https://stackoverflow.com/questions/15141762/how-to-initialize-javascript-date-to-a-particular-timezone – venimus Sep 05 '17 at 08:27

2 Answers2

0

There is no issue. Javascript is a client side language, so will tell you the client's date.

joshua miller
  • 1,686
  • 1
  • 13
  • 22
-1

Sorry but I think thats the intended behaviour. If you convert this to a timestamp it will be the same.

Simon Appelt
  • 305
  • 4
  • 12