Converting Date to EST/EDT Timezone

Java supports three timezone constants for Eastern Standard Time i.e. "EST", "America/New_York" and "EST5EDT". It is very important to understand the difference between them to correctly utilize these constants for converting date or time in Eastern Standard Time values.

1. Difference between EST, EST5EDT and ‘America/New_York’

In the eastern part of the USA, timezone offsets are different during summer and winter.

  1. During winter, time is EST. EST is always UTC-5 hours and without consideration for DST (daylight savings time).
  2. During summer, time is EDT. EDT is UTC-4 hours and with DST.
  3. To correctly represent time, during whole year, we should call it ET (Eastern Time) which include EST and EDT both.
  4. From timezone perspective, EST5EDT means either in EST or EDT. It specifies that the zone uses a standard time of UT-5h called “EST”, a DST of UT-4h called “EDT”, and switches between them, annually.
  5. The time zone America/New_York is the same as EST5EDT for all dates after the ‘Uniform Time Act of 1966‘.
  6. So if we are not using dates before 1966 in our application, then we should use America/New_York timezone. It is preferred way.

Always, prefer to use 'America/New_York' for Eastern time. And use ‘ET’ in formatted timestamp. It represents EST and EDT both.

2. Convert Date Time to ET Timezone

Let us see how to convert a given date-time to an instant in the ET timezone.

2.1. ZonedDateTime

Java program to convert ZonedDateTime in ET timezone.

DateTimeFormatter globalFormat = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mma z");
DateTimeFormatter etFormat = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mma 'ET'");

ZonedDateTime currentISTime = ZonedDateTime.now(); // "Asia/Kolkata"
ZonedDateTime currentETime = currentISTime
      .withZoneSameInstant(ZoneId.of("America/New_York")); //ET Time

System.out.println(globalFormat.format(currentETime));
System.out.println(etFormat.format(currentETime));

Watch the output:

02/16/2022 at 08:27am GMT-05:00
02/16/2022 at 08:27am ET

2.2. java.util.Date and Calendar

Java program to print Date in ET timezone.

SimpleDateFormat etDf = new SimpleDateFormat("MM/dd/yyyy 'at' hh:mma 'ET'");
TimeZone etTimeZone = TimeZone.getTimeZone("America/New_York");
etDf.setTimeZone( etTimeZone );

Date currentDate = new Date();
Calendar currentTime = Calendar.getInstance();

//In ET Time
System.out.println(etDf.format(currentDate.getTime()));
System.out.println(etDf.format(currentTime.getTimeInMillis()));

Watch the output:

02/16/2022 at 08:27am ET
02/16/2022 at 08:27am ET

Drop me your questions in the comments section regarding converting the date to EST in Java.

Happy Learning !!

Sourcecode on Github

Comments

Subscribe
Notify of
guest
9 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode