Skip to content
Advertisement

How to convert String to UTC timezone?

I have a string like this,

String userTime = "12-09-2022 08:21:32 EST"

I have a utility which converts this string to UTC time

DateTimeFormatter f = DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm:ss z");
ZonedDateTime zdt = ZonedDateTime.parse(userTime, f).withZoneSameInstant(ZoneOffset.UTC);

This returns the result 2022-12-09T12:21:32Z

It gives back the time difference of 4 hours. Shouldn’t it be 5 hours?

Advertisement

Answer

There is a time change in EST timezone on October 30th, try in September and you have only 4 hours difference and 5 hours in December.

Your can try this on this website: https://savvytime.com/converter/est-to-utc/sep-12-2022/8-30am

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