Search code examples
javascriptdatetimetimezoneutcpst

How to convert PST timezone date to Local TimeZone in Javascript?


I'm getting the date in PST TimeZone and need to convert it to local TimeZone. I'm developing a product in CRM so TimeZone can be changed user to user.

I tried to use moment JS but for that, we need to specify the country/ city name and all I'm getting is TimeZoneOffset. I have a code for UTC to local time zone if it gets converted to UTC also then my work will be done.

Fri Jan 17 2020 22:57:49 GMT-0800 (Pacific Standard Time) Need the answer in TS if possible or JS will be ok. Thank you.


Solution

  • To Convert other time zones to local time zone. You can use the following in javascript.

    var date = new Date(other time zone value);
    date.toString();
    

    For example

    var date = new Date('Fri Jan 17 2020 22:57:49 GMT-0800 (Pacific Standard Time)');
    date.toString();
    

    result will be "Sat Jan 18 2020 12:27:49 GMT+0530 (India Standard Time)"