Home > Software engineering >  How to convert String to UTC timezone?
How to convert String to UTC timezone?

Time:11-23

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?

CodePudding user response:

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

  • Related