XMLGregorianCalendar in java, with NO Timezone
Asked Answered
M

1

14

How do I create an XMLGregorianCalendar without a timezone? No time offset (0) == UTC which outputs a 'Z' in the output. The meaning of my field is implicit local time, where locality is specified elsewhere on the xml record (such as address).

How do I create an XMLGregorianCalendar with undefined timezone (TimeZone indeterminate)?

Valid XML ISO-8601 Gregorian Calendar formats include:

  • CCYY-MM-DDThh:mm:ss – without Zulu time designator or TimeOffset refers to the local time of the relative physical location.
  • CCYY-MM-DDThh:mm:ssZ – the DateTime for the relative physical location is expressed in UTC (Zulu) time, for local time a conversion must take place.
  • CCYY-MM-DDThh:mm:ss+05:30 the DateTime for the relative physical location is expressed in some time zone which is +5 hours and 30 minutes offset from UTC. For local time we must first convert to UTC, then to local time by offsetting from UTC. There is no guarantee that the provided location is local time for the record location.
Muscatel answered 30/11, 2017 at 0:47 Comment(0)
B
20

I looked at the documentation of XMLGregorianCalendar. In the table at the top, the bottom row, it says that the timezone is

Number of minutes or DatatypeConstants.FIELD_UNDEFINED.

So let’s try the latter option:

    System.out.println(xcal);
    xcal.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
    System.out.println(xcal);

In one test run this printed:

2017-11-30T07:54:05.647+01:00
2017-11-30T07:54:05.647

After I set the time zone to undefined, it no longer prints the offset. So I believe I have obtained what you want.

Beluga answered 30/11, 2017 at 6:59 Comment(1)
Thank you - I should have closed this question last night already, I discovered this myself about 5 minutes after posting the question. Points awarded for work done.Muscatel

© 2022 - 2024 — McMap. All rights reserved.