Java Utililty Methods String to Date

List of utility methods to do String to Date

Description

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

Method

DatetoDate(final String _text, final String _dateFormat)
Convert a string into a date type.
SimpleDateFormat formatter = new SimpleDateFormat(_dateFormat);
try {
    return formatter.parse(_text);
} catch (ParseException ex) {
    throw new RuntimeException(ex);
DatetoDate(final String date, final String time)
to Date
try {
    return new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(date + " " + time);
} catch (ParseException e) {
    throw new RuntimeException(e);
DatetoDate(final String dateString, final String format)
to Date
if (dateString == null || dateString.isEmpty()) {
    return null;
final SimpleDateFormat sdf = getSimpleDateFormat(format);
Date date = null;
if (dateString != null) {
    date = sdf.parse(dateString);
return date;
DatetoDate(final String dateString, final String pattern)
to Date
final SimpleDateFormat sdf = new SimpleDateFormat(pattern);
try {
    return sdf.parse(dateString);
} catch (final Exception e) {
    return null;
DatetoDate(int date, String timeFormat)
to Date
StringBuilder sbBuilder = new StringBuilder();
if (!yyyyMMdd.equals(timeFormat) && String.valueOf(date).length() == 8) {
    sbBuilder.append("0");
sbBuilder.append(date);
DateFormat sdf = new SimpleDateFormat(timeFormat);
Date datetime = new Date();
try {
...
DatetoDate(long value, String format)
to Date
SimpleDateFormat fmt = new SimpleDateFormat(format);
Date date = null;
try {
    date = fmt.parse(Long.toString(value));
} catch (ParseException e) {
    e.printStackTrace();
return date;
...
MaptoDate(Map filter, String field)
to Date
return toDate(filter, field, null, MODO_NOP);
DatetoDate(Object v, String format, Date defaultValue)
to Date
if (v == null) {
    return defaultValue;
} else {
    if (v instanceof Date) {
        return (Date) v;
    } else if (v.getClass() == Long.class || v.getClass() == long.class) {
        return new Date((Long) v);
    } else {
...
DatetoDate(Object value, String format)
Convert the specified object into a Date.
if (value == null)
    return null;
if (value instanceof String) {
    try {
        return new SimpleDateFormat(format).parse((String) value);
    } catch (ParseException e) {
        throw new RuntimeException(
                "The value " + value + "with format " + format + " can't be converted to a Date", e);
...
DatetoDate(String createdAt)
to Date
try {
    return createLocalFormat().parse(createdAt);
} catch (ParseException ex) {
    throw new RuntimeException(ex);