Java Utililty Methods Date Parse

List of utility methods to do Date Parse

Description

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

Method

StringasDate(Date date, String format)
Formats a Date based on the provided format.
return asDate(date, format, "Unknown");
StringasDate(final long time)
as Date
if (time > 0) {
    return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(time));
} else {
    return "-";
DateasDate(final Map map, final String key)
as Date
final Object value = map.get(key);
if (value == null) {
    return null;
if (value instanceof String) {
    try {
        return dateFormat().parse((String) value);
    } catch (ParseException ex) {
...
CalendarasDate(final String literal)
Method formats the given literal as date literal.
Date date = null;
for (String pattern : datePatterns) {
    try {
        date = new SimpleDateFormat(pattern).parse(literal);
    } catch (ParseException e) {
if (date == null) {
...
DateasDate(String date)
as Date
try {
    return DATE_FORMAT.parse(date);
} catch (Exception e) {
    return null;
DateasDate(String param, SimpleDateFormat format)
as Date
if (param == null) {
    return null;
if (param instanceof String) {
    try {
        return format.parse(param);
    } catch (ParseException e) {
        throw new IllegalArgumentException(
...
DateasDate(String s)
as Date
if ("\"N/A\"".equals(s)) 
    return null;
return FMT_TRADE_DATE.get().parse(s);
DateasDate(String string)

asDate.

try {
    if (isIsoFormat(string)) {
        throw new RuntimeException("Date does not fit into ISO date format.");
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = simpleDateFormat.parse(string);
    return date;
} catch (ParseException parseException) {
...
DateasDate(String value, String format)
as Date
SimpleDateFormat df = new SimpleDateFormat(format);
df.setLenient(false);
try {
    ParsePosition pp = new ParsePosition(0);
    Date d = df.parse(value, pp);
    if (pp.getIndex() != value.length()) {
        d = null;
    return d;
} catch (Exception e) {
    return null;
StringconvertDateForExcel(String timestamp)
Converts the time from FLAME format to Excel-friendly format
SimpleDateFormat date_format = new SimpleDateFormat(flameDateFormat);
SimpleDateFormat excel_format = new SimpleDateFormat(excelDateFormat);
Calendar c = Calendar.getInstance();
c.setTime(date_format.parse(timestamp));
return excel_format.format(c.getTime());