0

I've got a DateTime object in GMT, and I'd like to convert it to EST, which is my local timezone. How can I do this?

I'm confused because since EST is my local timezone, java is assuming that any DateTime objects are already in EST and so new DateTime(refDate, DateTimeZone.forID('EST')) isn't converting anything.

Steve
  • 4,457
  • 12
  • 48
  • 89

1 Answers1

0

Since your Date is in GMT format, first you need to parse the Date using UTC, then convert it into your local time zone.

        String gmtTime = "2015-05-28 11:36:38.0";

        DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.S");
        DateTime dateTime = fmt.withZoneUTC().parseDateTime(gmtTime);
        System.out.println("UTC Time: "+dateTime);

        DateTime now = dateTime.toDateTime(DateTimeZone.forID("EST"));
        System.out.println("Current EST Time " +now);

Output

UTC Time: 2015-05-28T11:36:38.000Z
Current EST Time 2015-05-28T06:36:38.000-05:00
K139
  • 3,654
  • 13
  • 17