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

DatestrToDate(final String str)
str To Date
try {
    return DATE_FORMAT.parse(str);
} catch (ParseException e) {
    throw new RuntimeException(e.getMessage() + " Caused by " + e.getCause(), e);
DatestrToDate(String _date, String format)
str To Date
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.parse(_date);
DatestrToDate(String date)
str To Date
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd");
java.util.Date d = sdf.parse(date);
return d;
DatestrToDate(String date)
str To Date
if (date == null) {
    return null;
Date realDate = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
    Date newDate = sdf.parse(date);
    String str = sdf.format(newDate);
...
DatestrToDate(String date, String pattern)
str To Date
SimpleDateFormat format = new SimpleDateFormat(pattern);
try {
    return format.parse(date);
} catch (ParseException e) {
    e.printStackTrace();
return null;
DateStrToDate(String dateFormat)
Str To Date
SimpleDateFormat formatter = new SimpleDateFormat("EEEE, MMM dd, yyyy HH:mm:ss a");
try {
    return formatter.parse(dateFormat);
} catch (ParseException e) {
    e.printStackTrace();
return null;
DatestrToDate(String dateInString)
Convierte una fecha tipo string a un tipo Date
Date newDate = null;
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
if (dateInString != null) {
    try {
        newDate = sdf.parse(dateInString);
    } catch (ParseException ex) {
        ex.printStackTrace();
return newDate;
DatestrToDate(String dateStr, String dateFormat)
str To Date
if (dateStr == null || "".equals(dateStr.trim()))
    return null;
DateFormat dt = null;
if (dateFormat == null) {
    dt = getDateFormat(dateStr);
} else {
    dt = new SimpleDateFormat(dateFormat);
return dt.parse(dateStr);
DatestrToDate(String dateStr, String format)
str To Date
SimpleDateFormat formater = new SimpleDateFormat(format);
Date date = formater.parse(dateStr);
return date;
DatestrToDate(String format, String dateStr)
str To Date
Date date = null;
try {
    if (yyyyMMdd.equals(format)) {
        date = dateFormat.parse(dateStr);
    } else if (yyyy_MM_dd.equals(format)) {
        date = dateFormat2.parse(dateStr);
    } else if (ddMMyy.equals(format)) {
        date = dateFormat3.parse(dateStr);
...