BillMan
BillMan

Reputation: 9924

Convert UTC to Eastern Prevailing Time (EDT or EST)

Can someone tell me how I can convert a UTC date in JodaTime to Eastern Prevailing Time (which is EST or EDT depending on the time of year?)

Upvotes: 3

Views: 5388

Answers (2)

Bojan Petkovic
Bojan Petkovic

Reputation: 2576

Joda takes care of it by itself. There is a slight difference between using the TimeZone and the Locale of a place.

Take a look at the following examples.

Using Locale:

Using @BillMan's suggestion setting DateTimeZone to a locale will actually change the time zone.

System.out.println("Winter " + DateTime.now(DateTimeZone.UTC).parse("2015-12-01T12:00:00").toDateTime(DateTimeZone.forID("America/New_York")).toString());
System.out.println("Summer " + DateTime.now(DateTimeZone.UTC).parse("2015-05-01T12:00:00").toDateTime(DateTimeZone.forID("America/New_York")).toString());

Returned:

Winter 2015-12-01T12:00:00.000-05:00
Summer 2015-05-01T12:00:00.000-04:00

Using TimeZone:

Note that both times are set to 12:00:00, and the result in Summer got moved by an hour, (but the offset stayed the same)

System.out.println("Winter " + DateTime.now(DateTimeZone.UTC).parse("2015-12-01T12:00:00").toDateTime(DateTimeZone.forID("EST")).toString());
System.out.println("Summer " + DateTime.now(DateTimeZone.UTC).parse("2015-05-01T12:00:00").toDateTime(DateTimeZone.forID("EST")).toString());

Returned:

 Winter 2015-12-01T12:00:00.000-05:00
 Summer 2015-05-01T11:00:00.000-05:00

Upvotes: 3

JodaStephen
JodaStephen

Reputation: 63355

Use withZone() to convert a Joda-Time object to a different time-zone.

Upvotes: 4

Related Questions