Skip to content
Advertisement

Converting date from one timezone to other timezone using ISO date string

I want to convert a date(10/14/2022 8:04 PM) from America/New_York timezone
to Asia/Tokyo‘timezone as shown below.
I have used ISO format with ‘Asia/Tokyo’ timezone. But I am getting one hour less after conversion
because 08:04:00 p.m. Friday October 14, 2022 in America/New_York
converts to 09:04:00 a.m. Saturday October 15, 2022 in Asia/Tokyo.

Even for other timeZone I have also tried but problem is same.
Please help me to understand the problem in this code

JavaScript

Result is: 2022. 10. 14. 20시 4분 0초

Advertisement

Answer

New York time zone is -4 hours (not +9hours) as yours.
see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

In your case of — 10/14/2022 8:04 PM at America/New_York:

JavaScript
JavaScript

As you can see, there is no conversion to do. Just set the correct date value indicating its original timezone offset (take care of possible daylight saving time [DST]).
Then just display your date/time with the local values you want.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement