• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sreejith Sreekumar
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2940
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Sreejith,

Please check your private messages.
 
Peer Reynders
Bartender
Posts: 2940
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic