Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLGregorianCalendar in java, with NO Timezone

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.
like image 529
Inquisitor Shm Avatar asked Nov 30 '17 00:11

Inquisitor Shm


1 Answers

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.

like image 62
Ole V.V. Avatar answered Oct 08 '22 08:10

Ole V.V.