I've java schema objects generated from xsd schema using JAXB.
What I'm trying to do is set the values of xml tags using java schema object setter methods and then marshall the java objects. On the final xml generated though, I see that the timestamp generated for xs:datetime types does not have milliseconds.
I'm expecting to see a date like "2013-06-28T01:20:50.000-04:00", all I'm getting is "2013-06-28T01:20:50-04:00" without milliseconds.
Setter call
obj.setTransactionDateTime(getTimestamp("2013-06-28 01:20:50"));
getTimestamp method
public Calendar getTimestamp(String dateStr)
{
Date returnDate = null;
if(dateStr == null)
{
return null;
}
try
{
SimpleDateFormat srcFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = srcFormatter.parse(dateStr);
SimpleDateFormat destFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
returnDate = destFormatter.parse(destFormatter.format(date));
}
catch (ParseException e)
{
dbacc.logError("Error while parsing date string" + e.getMessage());
}
Calendar cal = Calendar.getInstance();
cal.setTime(returnDate);
return cal;
}
Binding for datetime types defined as follows...
<jxb:javaType name="java.util.Calendar" xmlType="xsd:dateTime" parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" printMethod="javax.xml.bind.DatatypeConverter.printDateTime"/>
Not sure what's wrong with the code. Any help is much appreciated.