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

XMLGregorianCalendarcreateXMLGregorianCalendar(Date currentDateTime)
create XML Gregorian Calendar
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(currentDateTime);
XMLGregorianCalendar createDate;
try {
    createDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
    createDate.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
    createDate.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
} catch (DatatypeConfigurationException e) {
...
XMLGregorianCalendarcreateXmlGregorianCalendar(Date date)
Converts the data to an XMLGregorianCalendar in the GMT time zone.
if (date == null) {
    return null;
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
return getDatatypeFactory().newXMLGregorianCalendar(calendar);
XMLGregorianCalendarcreateXMLGregorianCalendar(final Date date)
Converts a given Date to a new XMLGregorianCalendar .
if (date == null) {
    return null;
final GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
try {
    XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance()
            .newXMLGregorianCalendar(calendar);
...
XMLGregorianCalendarcreateXMLGregorianCalendar(final Date time)
create XML Gregorian Calendar
GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
c.setTime(time);
return DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
StringdateToString(Calendar calendar)
Formats the given date into its string representation according to the ISO 8601 (e.g.
GregorianCalendar utcCalendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
utcCalendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
XMLGregorianCalendar xmlCalendar = dtFactory.newXMLGregorianCalendar(utcCalendar);
xmlCalendar = xmlCalendar.normalize();
return xmlCalendar.toXMLFormat();
XMLGregorianCalendardateToXml(Date date)
date To Xml
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
XMLGregorianCalendar sdate = null;
try {
    sdate = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    sdate.setYear(calendar.get(Calendar.YEAR));
    sdate.setMonth(calendar.get(Calendar.MONTH) + 1);
    sdate.setDay(calendar.get(Calendar.DAY_OF_MONTH));
...
XMLGregorianCalendarDateToXmlCalendar(Date date)
Date To Xml Calendar
GregorianCalendar calendar;
calendar = new GregorianCalendar(getDefaultTimeZone());
calendar.setTime(date);
try {
    DatatypeFactory factory = DatatypeFactory.newInstance();
    return factory.newXMLGregorianCalendar(calendar);
} catch (DatatypeConfigurationException e) {
    return null;
...
XMLGregorianCalendardateToXmlDate(Date date)
date To Xml Date
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
XMLGregorianCalendar gc = null;
try {
    gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
} catch (Exception e) {
    e.printStackTrace();
return gc;
XMLGregorianCalendardateToXMLGC(Date fecha)
metodo que convierte de date a xmlGregorianCalendar
XMLGregorianCalendar dateResult = null;
if (fecha == null) {
    dateResult = null;
} else {
    try {
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(fecha);
        dateResult = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
...
XMLGregorianCalendardateToXmlGregorian(Date timestamp)
date To Xml Gregorian
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(timestamp);
XMLGregorianCalendar xmlCalendar = null;
xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
return xmlCalendar;