I'm getting a string and trying to convert it to a XMLGregorianCalendar but I'm getting a wrong result.
current code:
Flight flight = new flight();
XMLGregorianCalendar result = null;
Date date = null;
SimpleDateFormat simpleDateFormat;
GregorianCalendar gregorianCalendar;
try {
simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
date = simpleDateFormat.parse(flightDate);
gregorianCalendar = (GregorianCalendar)GregorianCalendar.getInstance();
gregorianCalendar.setTime(date);
result = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
} catch (ParseException ex) {
Logger.getLogger(FlightBookings.class.getName()).log(Level.SEVERE, null, ex);
} catch (DatatypeConfigurationException ex) {
Logger.getLogger(FlightBookings.class.getName()).log(Level.SEVERE, null, ex);
}
flight.setDate(result);
So my flight object has this attribute:
protected XMLGregorianCalendar date;
and this function to set it:
public void setDate(XMLGregorianCalendar value) {
this.date = value;
}
When I then print out the flight
objects date using this:
System.out.println(flight.getDate());
I get this:
2014-06-04T09:15:00.000+01:00
But when I marshall it to an XML document using jaxbm, the value shown in XML is:
2014-06-04+01:00
The result I want to save to the XML field should look like this:
04/06/2014 09:15
Any ideas what is going wrong? Thanks.
No comments:
Post a Comment