Java Utililty Methods XML Date

List of utility methods to do XML Date

Description

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

Method

DateconvertDate(String date)
convert Date
return DatatypeConverter.parseDateTime(date).getTime();
DoubledateToDouble(Object value)
date To Double
Double ret = new Double(0.);
if (value != null && value instanceof String) {
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    try {
        Calendar cal = DatatypeConverter.parseDateTime((String) value);
        long diff = cal.getTimeInMillis() + 2209161600000l; 
        ret = diff / 86400000.;
    } catch (IllegalArgumentException e) {
...
StringdateToString(Date date)
date To String
if (date == null)
    throw new IllegalArgumentException("date cannot be null");
Calendar cal = Calendar.getInstance();
cal.setTime(date);
String result = DatatypeConverter.printDateTime(cal);
if (result.length() < 16)
    return result;
else
...
StringdateToString(Date date)
date To String
Calendar c = Calendar.getInstance(ENCODING_TIME_ZONE, Locale.ENGLISH);
c.setTime(date);
return DatatypeConverter.printDateTime(c);
StringdateToXsdDateTime(Date date)
Converts a Date object to the corresponding XSD DateTime String.
Calendar calendar = GregorianCalendar.getInstance();
calendar.setTime(date);
return DatatypeConverter.printDateTime(calendar);
longextractXsdDatetime(String string)
Extracts the timestamp of a XsdDateTime string.
return DatatypeConverter.parseDateTime(string).getTimeInMillis();
StringformatXmlDate(Calendar cal)
Formats a calendar into an XML-formatted date only (without the time).
if (cal == null) {
    return "null";
return DatatypeConverter.printDate(cal).substring(0, 10);
StringgetDateTimeRepresentation(Calendar date)
Given a Calendar instance, returns its String representation according to XSD standards.
return null != date ? DatatypeConverter.printDateTime(date) : "";
StringgetDateTimeString(Date dateTime)
get Date Time String
Calendar cal = Calendar.getInstance();
if (dateTime != null) {
    cal.setTime(dateTime);
return DatatypeConverter.printDateTime(cal);
StringgetXMLDate(final Date date)
Converts Date into XML-Tag with type xsd:dateTime
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return DatatypeConverter.printDateTime(calendar);