I am dealing with a situation where I want to convert java.util date into soap supported format with specific zone (Europe/Brussels)
I tried using Java 8 zone id feature but it seems it works well with instant dates only.
ZoneId zoneId = ZoneId.of("Europe/Brussels");
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.now(),
zoneId);
GregorianCalendar calendar = GregorianCalendar.from(zonedDateTime);
String xmlNow = convertToSoapDateFormat(calendar);
calendar.add(Calendar.MINUTE, 61);
String xmlLater = convertToSoapDateFormat(calendar);
//Method for soap conversion
private String convertToSoapDateFormat(GregorianCalendar cal) throws DatatypeConfigurationException {
XMLGregorianCalendar gDateFormatted2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(
cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND),
DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED);
return gDateFormatted2.toString();// + "Z";
}
I want lets say this date (2002-02-06) converted to this SOAP format 2002-02-06T08:00:00