aspose file tools*
The moose likes Web Services and the fly likes Jaxb2. 0 - How to display +00:00 instead of Z in timezone info ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Jaxb2. 0 - How to display +00:00 instead of Z in timezone info ?" Watch "Jaxb2. 0 - How to display +00:00 instead of Z in timezone info ?" New topic
Author

Jaxb2. 0 - How to display +00:00 instead of Z in timezone info ?

Sreejith Sreekumar
Greenhorn

Joined: Feb 04, 2008
Posts: 2
I was using Jaxb1.0/jdk1.4 in my application to convert java objects to xml. The date-time used to be output in the format 2008-02-04T15:04:48+00:00.

I upgraded to Jaxb2.0 /jdk1.5 and am getting the output in the format 2008-02-04T15:04:48. ie the timezone information is lost. I tried to do a setTimezone on the xMLGregorianCalendar object but then it returns a format with an Z (eg: 2008-01-22T01:40:00Z) appended. Of course the Z component is equivalent to the +/-aa:bb but unfortunately the other application that uses the generated xml is built to specifically extract the timezone information from the +/-aa:bb component.

Is is possible to specify that the tmz info should be displayed in the format +/-aa:bb rather than Z ?

Thanks
Sreejith
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
Welcome to JavaRanch Sreejith,

Please check your private messages.


"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
You may need to consider creating a new class which extends XMLGregorianCalendar which contains the instance of XMLGregorianCalendar which holds the time.
Override the toXMLFormat method to alter the zone offset returned and delegate all the other methods to the contained instance.
Before marshalling replace the affected XMLGregorianCalendar instances with CustomXMLGregorianCalendar instances.




[ February 04, 2008: Message edited by: Peer Reynders ]
Gadi Sh
Greenhorn

Joined: Oct 25, 2010
Posts: 2
You can use this:

DatatypeFactory df;
try {
df = DatatypeFactory.newInstance();
return df.newXMLGregorianCalendar(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
} catch (DatatypeConfigurationException e) {
throw new SomeRuntimeException(e);
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jaxb2. 0 - How to display +00:00 instead of Z in timezone info ?
 
Similar Threads
Parsing XML datetime in Android
Changing the timezone of a date, not only display
Convert Local time to UTC and vice versa
smartcardio.CardException: Card cryptogram invalid
Time Zone problem