Java Utililty Methods XML Date Create

List of utility methods to do XML Date Create

Description

The list of methods to do XML Date Create are organized into topic(s).

Method

XMLGregorianCalendartoXmlDateTime(GregorianCalendar cal)
Converts a GregorianCalendar to a XMLGregorianCalendar date time.
return datatypeFactory.newXMLGregorianCalendar(cal);
XMLGregorianCalendartoXmlDateTimeUTC(Date date)
Returns a XMLGregorianCalender (xml:dateTime) in UTC
if (date != null) {
    GregorianCalendar cal = new GregorianCalendar(UTC);
    cal.setTime(date);
    return factory.newXMLGregorianCalendar(cal);
} else {
    return null;
XMLGregorianCalendartoXMLGregorianCalendar(Date date)
to XML Gregorian Calendar
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
XMLGregorianCalendartoXMLGregorianCalendar(Date date)
Converts Date to XMLGregorianCalendar
GregorianCalendar gCalendar = new GregorianCalendar();
gCalendar.setTime(date);
XMLGregorianCalendar xmlCalendar = null;
try {
    xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gCalendar);
} catch (DatatypeConfigurationException ex) {
return xmlCalendar;
...
XMLGregorianCalendartoXMLGregorianCalendar(Date date, TimeZone timeZone, Locale locale)
to XML Gregorian Calendar
if (date == null) {
    return null;
return toXMLGregorianCalendar(date.getTime(), timeZone, locale);
XMLGregorianCalendartoXmlGregorianCalendar(GregorianCalendar calendar)
to Xml Gregorian Calendar
XMLGregorianCalendar xmlGregorianCalendar;
DatatypeFactory datatypeFactory;
try {
    datatypeFactory = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
    throw new RuntimeException(e);
xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(calendar);
...
XMLGregorianCalendartoXMLGregorianCalendar(long dateInMillis)
to XML Gregorian Calendar
java.util.Date date = new java.util.Date(dateInMillis);
return toXMLGregorianCalendar(date);
XMLGregorianCalendartoXMLGregorianCalendar(long timestamp)
to XML Gregorian Calendar
GregorianCalendar gc = new GregorianCalendar(GMT_TIME_ZONE);
gc.setTimeInMillis(timestamp);
try {
    return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
} catch (DatatypeConfigurationException e) {
    e.printStackTrace();
    return null;
XMLGregorianCalendartoXMLGregorianCalendar(String stringTypeDate)
to XML Gregorian Calendar
String yyyy = stringTypeDate.substring(0, 4);
String mm = stringTypeDate.substring(5, 7);
String dd = stringTypeDate.substring(8, 10);
String hh = stringTypeDate.substring(11, 13);
String mi = stringTypeDate.substring(14, 16);
String ss = stringTypeDate.substring(17, 19);
int iyyyy = Integer.parseInt(yyyy);
int imm = Integer.parseInt(mm);
...
XMLGregorianCalendartoXMLGregorianCalendar(Timestamp timestamp)
to XML Gregorian Calendar
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(timestamp);
XMLGregorianCalendar result = datatypeFactory.newXMLGregorianCalendar(calendar);
result.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
result.setFractionalSecond(new BigDecimal(timestamp.getNanos()).divide(new BigDecimal(1000000000)));
return result;