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

java.util.DatestrToDate(String i_StrDate, String i_Format)
str To Date
SimpleDateFormat SDF_My = new SimpleDateFormat(i_Format);
try {
    return SDF_My.parse(i_StrDate);
} catch (ParseException e) {
    throw e;
DatestrToDate(String input, String format)
str To Date
try {
    SimpleDateFormat df = new SimpleDateFormat(format);
    return df.parse(input);
} catch (Exception e) {
    return null;
DatestrToDate(String s, Date defaultValue)
Convert a 'String' to a 'Date', using DateFormat.getDateInstance().parse(s).
try {
    return DateFormat.getDateInstance().parse(s);
} catch (Exception e) {
return defaultValue;
DatestrToDate(String str)
str To Date
if (isEmpty(str)) {
    return null;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
    if (str.length() != 19) {
        return null;
    return dateFormat.parse(str);
} catch (ParseException e) {
    return null;
java.util.DatestrToDate(String str, String format, java.util.Date defaultValue)
str To Date
SimpleDateFormat fmt = new SimpleDateFormat(format);
try {
    defaultValue = fmt.parse(str);
} catch (Exception localException) {
return defaultValue;
DatestrToDate(String strD)
Convert string to date object
try {
    String strFormat = "yyyy-MM-dd   HH:mm:ss";
    SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
    return sdf.parse(strD);
} catch (java.text.ParseException e) {
    return new Date();
DatestrToDate(String strDate)
str To Date
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(strDate, pos);
return strtodate;
DatestrToDate(String strDate)
str To Date
if (strToSimpleFormat(strDate) != null) {
    return strToSimpleFormat(strDate);
} else {
    return strToDtSimpleFormat(strDate);
DatestrToDate(String strDate)
str To Date
ParsePosition pos = new ParsePosition(0);
return new SimpleDateFormat(FORMAT_YMD).parse(strDate, pos);
DatestrToDate(String strDate, String format)
str To Date
if (strDate == null) {
    return null;
SimpleDateFormat formatter = new SimpleDateFormat(format);
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(strDate, pos);
return strtodate;