0

I have a the XMLGregorianCalendar instance and I need to set the timezone to the "America/New_York". The class has a method to set the timezone. AS the Greenwich Mean Time is 4 hours ahead of Eastern Time, does it set like this to the "America/New_York" timezone?

gregorianCalendar.setTimezone(-4);
Arefe
  • 11,321
  • 18
  • 114
  • 168

1 Answers1

0

I have come with this solution lately and works fine for me.

Date date = format.parse(beginTime);

        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);

        XMLGregorianCalendar xmlGregCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);

        TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
        int minutes = timeZone.getOffset(cal.getTimeInMillis()) / 1000 / 60;
        xmlGregCal.setTimezone(minutes);
Arefe
  • 11,321
  • 18
  • 114
  • 168