0

I tried different ways but nothing worked as expected.

My first try:

let off= new Date().getTimezoneOffset()/60;

which gives -5.5

My second try

let off = new Date().toString().split("GMT")[1].split(" (")[0]

which gives +0530 as the new Date() gives Mon Apr 20 2020 12:10:22 GMT+0530 (India Standard Time)

What i need is +05.30 from the timezone.

FortuneCookie
  • 1,756
  • 3
  • 25
  • 41
  • The answer in the dup post has what you are looking for. It starts with the output of your first approach, and then formats it correctly. Don't do what you attempted in your second approach - that would rely on implementation specific output, which will vary across browsers. – Matt Johnson-Pint Apr 20 '20 at 16:32
  • Also, be sure to recognize that the offset you retrieve may be different for different points in time. By calling it against `new Date()`, you're asking for the user's *current* offset. This is especially important in time zones that have DST, but also applies to changes in standard time. Please read [the timezone tag wiki](https://stackoverflow.com/tags/timezone/info), especially the section titled "Time Zone != Offset". Thanks. – Matt Johnson-Pint Apr 20 '20 at 16:34

0 Answers0