I need to convert a local timezone to Pacific/Los angeles.
Example, if user in Hawaii
Code: taken here from https://stackoverflow.com/a/54127122/15358601
function convertTZ(date, tzString) {
return new Date((typeof date === "string" ? New Date(date) : date).toLocaleString("en-US", {timeZone: tzString}));
}
convertTZ(new Date(), "America/Los_Angeles")
Sun Mar 14 2021 17:01:59 GMT-1000 (Hawaii-Aleutian Standard Time) {}
It still prints the final with Hawaii. I need America/Los Angeles Display, not Hawaii. (however it still prints the correct new Hours and Minutes, just the Display label is incorrect) How can this be done?
The solution should work for other timezones also, printing it respectively its other timezone, eg: America/New_York, Europe/London, Europe/Paris, etc ,