1

How can i create a utc timestamp from a given date to different timezone.

For eg:

My system timezone is currently 'America/Denver' MST and i want to create a UTC timestamp for 'Asia/Kolkata'.

new Date('2020-12-17 20:00').toLocaleString('en-US', { timeZone: 'Asia/Kolkata' })

this is giving me "12/18/2020, 8:30:00 AM" but expected result is "12/18/2020, 8:00:00 PM"

OUTPUT IN UTC:

"Fri, 18 Dec 2020 03:00:00 GMT"

Expected OUTPUT IN UTC: (Asia/kolkata)

"Fri, 17 Dec 2020 14:30:00 GMT"

How can i do that?

fstr001
  • 11
  • 3
  • 2
    A date object does not have timezone. There is only one timezone, that of your local environment. Don't use it, use `new Date(Date.UTC(2020, 12, 17, 20, 0))` or `new Date("Fri, 17 Dec 2020 14:30:00 GMT")` or `new Date("2020-12-17T14:30:00Z")` instead. – Bergi Dec 15 '20 at 13:35
  • `new Date('2020-12-17 20:00')` is fraught, see [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results). The date is parsed using your system settings (i.e. 'America/Denver'), then presented using the offset rules for the location 'Asia/Kolkata'. – RobG Dec 15 '20 at 23:43

0 Answers0