Convert UTC to EST timezone

I have to convert UTC timestamp data to EST timezone. Below code is working fine when timezone difference is -5Hrs but when I give UTC time like - 2018-04-15T21:27:31.000Z then it outputs as 2018-04-15 16:27:31 -0500 which is not correct. Output should be 2018-04-15 17:27:31 -0400. It always subtract -5hrs.

DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.000'Z'"); utcFormat.setTimeZone(TimeZone.getTimeZone("UTC")); DateFormat estFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); estFormat.setTimeZone(TimeZone.getTimeZone("EST")); try { String date1 = estFormat.format(utcFormat.parse("2018-04-15T21:27:31.000Z")); System.out.println("est time : "+date1); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } 
6

1 Answer

You seem to expect the time zone shorthand named "EST" to obey the daylight saving time change rules. It doesn't. "EST" is the name for a time zone which is GMT-5 at any time of the year.

To get time zone definitions that obey daylight saving time rules as expected, you'll be better off using the name of the main cities that use these time zones.

In your case, try "America/New_York"

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like