0

I have a datetime object received from server in the following format:

{"date":"2021-05-11 13:02:01.273000","timezone_type":3,"timezone":"UTC"}

I'm having trouble to get the correct date corresponding to the user browser how can I parse this date into a js date object with the right time zone calculations. I used to take only the date disregarding the time zone and it turned out to be wrong to the user

Girl Codes
  • 328
  • 4
  • 17
  • Try giving this a look [How to initialize a JavaScript Date to a particular time zone](https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone) – Anders May 11 '21 at 13:59

1 Answers1

0

Try using toLocaleString method and specify the timeZone:

x = JSON.parse(`{"date":"2021-05-11 13:02:01.273000","timezone_type":3,"timezone":"UTC"}`);
new Date(x.date).toLocaleString("en-US", {timeZone: x.timezone})
XMehdi01
  • 5,538
  • 2
  • 10
  • 34