I have a String date I am converting to a XMLGregorianCalendar
. The below code converts it with no errors. However, the system I pass the date to, gets the error reported below.
The following XMLGregorianCalendar
works:
The following XMLGregorianCalendar
does not work (the code below converts it to this):
Question
How do I convert the string to the required format?
public static void main(String []args){
try {
String commenceTOString = "2021-06-30 05:00:00";
java.util.Date dateCommence = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(commenceTOString);
System.out.println(dateCommence);
java.util.GregorianCalendar c = new java.util.GregorianCalendar();
c.setTime(dateCommence);
javax.xml.datatype.XMLGregorianCalendar commence = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
System.out.println(commence);
} catch (Exception e) {
e.printStackTrace();
}
}
Error
E: Message validation failed. Errors: [cvc-pattern-valid: Value '2021-06-30T06:30:00.000+02:00' is not facet-valid with respect to pattern '(((((0[1-9])|(1[0-2]))-((0[1-9])|(1\d)|(2[0-9])))|((((0[13578])|(1[02]))-31)|(((0[1,3-9])|(1[0-2]))-30)))|(((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((0[1,3-9])|(1[0-2]))-(29|30)))))T([0-1][0-9]|[2][0-3])(:([0-5][0-9])){1,2}' for type 'dateTime'.cvc-attribute.3: The value '2021-06-30T06:30:00.000+02:00' of attribute 'DepartureDateTime' on element 'FlightSegment' is not valid with respect to its type, 'dateTime'.]. http://www.elleipsis.com/booking/exception/35a8ac87-6743-4719-9504-a8a17a1a0471