Java Utililty Methods Parse Date

List of utility methods to do Parse Date

Description

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

Method

DateparseDate(String value)
parse Date
if (value == null || value.length() == 0) {
    return null;
} else if (value.length() == 4) {
    return getSimpleDateFormat(HL7TSFormat4).parse(value);
} else if (value.length() == 8) {
    return getSimpleDateFormat(HL7TSFormatL8).parse(value);
} else if (value.length() == 12) {
    return getSimpleDateFormat(HL7TSFormatL12).parse(value);
...
DateparseDate(String value)
Parse a date expression with both date and time information with full millisecond precision and create a Date .
try {
    return createDateFormat().parse(value);
} catch (ParseException e) {
    throw new IllegalArgumentException("Failed to parse date expression '" + value + "'", e);
DateparseDate(String value)
parse Date
Date date = null;
try {
    date = HEADER_DATE.parse(value);
} catch (Exception e) {
return date;
DateparseDate(String value)
Loops over all the possible date formats and tries to find the right one.
if (value == null) {
    return null;
Date date = null;
for (ThreadLocal<SimpleDateFormat> format : DATETIME_FORMATS) {
    try {
        date = format.get().parse(value);
        break;
...
DateparseDate(String value)
parse Date
Date[] dates = parseDate(new String[] { value });
if (dates != null && dates.length > 0)
    return dates[0];
return null;
DateparseDate(String value)
Attempts to parse a date in various formats.
for (int i = 0; i < DATE_FORMATS.length; i++) {
    SimpleDateFormat df = new SimpleDateFormat(DATE_FORMATS[i]);
    try {
        return df.parse(value);
    } catch (ParseException e) {
return null;
...
DateparseDate(String value, Class targetType, String... formats)
parse Date
for (String format : formats) {
    try {
        long v = new SimpleDateFormat(format).parse(value).getTime();
        return (Date) targetType.getConstructor(long.class).newInstance(v);
    } catch (ParseException e) {
    } catch (Exception e) {
        throw new RuntimeException(e);
    try {
        return (Date) targetType.getConstructor(String.class).newInstance(value);
    } catch (Exception e) {
throw new IllegalArgumentException(
        "cannot parse:" + value + " for date by formats:" + Arrays.asList(formats));
DateparseDate(String value, String formater)
parse Date
Date date = null;
sdf.applyPattern(formater);
try {
    date = sdf.parse(value);
} catch (ParseException e) {
    e.printStackTrace();
return date;
...
java.util.DateparseDate(String value, String pattern)
parse Date
try {
    TimeZone tz = TimeZone.getDefault();
    String dateFormat = pattern;
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
    sdf.setTimeZone(tz);
    java.util.Date parsed = null;
    parsed = sdf.parse(value);
    return parsed;
...
StringparseDate2String(Date date)
parse Date String
return parseDate2String(date, null);