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

DatestringToDate(String s, DateFormat formatter)
Convert a date time string (e.g., "2011-06-07 19:12:18") to a Date object.
try {
    return formatter.parse(s);
} catch (ParseException e) {
    return null;
DatestringToDate(String s, String format)
string To Date
return new SimpleDateFormat(format).parse(s);
DatestringToDate(String sDate)
string To Date
SimpleDateFormat stringToDate;
try {
    stringToDate = new SimpleDateFormat("dd/MM/yyyy");
    return stringToDate.parse(sDate);
} catch (ParseException e) {
    stringToDate = new SimpleDateFormat("yyyy-MM-dd");
    return stringToDate.parse(sDate);
java.util.DatestringToDate(String source)
string To Date
TimeZone localTimeZone = getDateFormatter().getTimeZone();
return stringToDate(source, localTimeZone);
DatestringToDate(String source, String format)
string To Date
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
    if (format.equals(YYYY_MM_DD_HH_MM_SS) || format.equals(DATE_PATTERN_SS)) {
        if (source.length() < INIT_DATE_TIME.length()) {
            source += INIT_DATE_TIME.substring(source.length() + 1);
    return sdf.parse(source);
...
DateStringToDate(String str)
String To Date
String _pattern = "yyyy-MM-dd";
return StringToDate(str, _pattern);
DatestringToDate(String str)
string To Date
if (str == null) {
    return null;
DateFormat defaultDate = DateFormat.getDateInstance();
Date date = null;
try {
    date = defaultDate.parse(str);
} catch (ParseException pe) {
...
DatestringToDate(String str, String format)
string To Date
if (str != null) {
    DateFormat dateFormat = new SimpleDateFormat(format);
    try {
        return dateFormat.parse(str);
    } catch (ParseException e) {
        return null;
return null;
DateStringToDate(String str, String format)
String To Date
if (str == null) {
    return null;
if (format == null) {
    format = "yyyy-MM-dd";
DateFormat df = new SimpleDateFormat(format);
return df.parse(str);
...
DatestringToDate(String str, String formatStr)
stringToDate.
DateFormat format = new SimpleDateFormat(formatStr);
return format.parse(str);