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

StringgetXSDDateTimeFromCalendar(Calendar calTime)
Take a Calendar object and return an xsd:dateTime format string.
String ret = null;
try {
    ret = DatatypeConverter.printDateTime(calTime);
} catch (Exception e) {
    e.printStackTrace();
return ret;
booleanisPreEIDAS(Date date)
is Pre EIDAS
return date != null && date.compareTo(EIDAS_DATE) < 0;
booleanisValidDateUpdatedType(Calendar value)
is Valid Date Updated Type
final Calendar min = DatatypeConverter.parseDateTime("2000-12-31T00:00:00");
return value != null && !value.before(min);
StringprintDate(final Calendar date)
print Date
date.setTimeZone(TimeZone.getTimeZone("UTC"));
return DatatypeConverter.printDateTime(date);
StringprintDate(java.util.Date dt)
print Date
if (dt == null) {
    return null;
Calendar c = Calendar.getInstance();
c.setTime(dt);
return DatatypeConverter.printDate(c);
StringprintDateTime(final Date date)
Formats a date value in a string, assuming UTC timezone and Canada locale.
if (date == null) {
    return null;
final Calendar calendar = CALENDAR.get();
calendar.setTime(date);
return DatatypeConverter.printDateTime(calendar);
StringprintDateUpdatedType(Calendar value)
print Date Updated Type
if (value == null || !isValidDateUpdatedType(value))
    throw new IllegalArgumentException("Can't print date-updated value!");
else
    return DatatypeConverter.printDateTime(value);
longstring2millis(String lexicalXSDDateTime)
Converts given string to milliseconds from Unix Epoch
long res;
try {
    res = javax.xml.bind.DatatypeConverter.parseDateTime(lexicalXSDDateTime).getTimeInMillis();
} catch (IllegalArgumentException e) {
    return -1;
return res;
DatetoDate(String date)
to Date
Calendar cal = DatatypeConverter.parseDateTime(date);
cal.setTimeZone(TimeZone.getTimeZone(TIMEZONE));
return cal.getTime();
DatetoJavaDate(String dateStr)
Converts a date string in [datetime] format to a java date
if (!DATE_PATTERN.matcher(dateStr).matches()) {
    return null;
try {
    return DatatypeConverter.parseDateTime(dateStr).getTime();
} catch (IllegalArgumentException e) {
    return null;