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 dateString)
String to date.
Date date;
if (!dateString.equalsIgnoreCase("")) {
    try {
        date = new SimpleDateFormat("dd MMM yyyy").parse(dateString);
        return date;
    } catch (ParseException e) {
return null;
DatestringToDate(String dateString)
string To Date
String[] formatStrings = { "yyyy-MM-dd hh:mm:ss", "yyyy-MM-dd hh:mm", "yyyy-MM-dd" };
Integer i = 0;
while (i < formatStrings.length) {
    try {
        return new SimpleDateFormat(formatStrings[i]).parse(dateString);
    } catch (Exception e) {
        i++;
return null;
DatestringToDate(String dateString)
convert a string to a date using the standard web service pattern Note that HH is 0-23
if (isBlank(dateString)) {
    return null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(WS_DATE_FORMAT);
try {
    return simpleDateFormat.parse(dateString);
} catch (ParseException e) {
    SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat(WS_DATE_FORMAT2);
...
DatestringToDate(String dateString)
string To Date
Date date = null;
try {
    date = df.parse(dateString);
} catch (ParseException e) {
    throw new RuntimeException(e);
return date;
DatestringToDate(String dateString, String dataFormat)
string To Date
if (isEmpty(dateString)) {
    return null;
if (dateString.length() != 14) {
    return null;
java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat(dataFormat);
try {
...
DatestringToDate(String dateString, String dateFormat)
string To Date
if ("".equals(dateString) || dateString == null) {
    return null;
try {
    return new SimpleDateFormat(dateFormat).parse(dateString);
} catch (Exception e) {
    return null;
DatestringTodate(String dateString, String format)
Convert string to date.
final DateFormat dateFormat = new SimpleDateFormat(format, Locale.US);
return dateFormat.parse(dateString);
DatestringToDate(String dateString, String formatStr)
string To Date
if (isNotEmpty(dateString) && isEmpty(formatStr)) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return dateFormat.parse(dateString);
} else if (isNotEmpty(dateString) && isNotEmpty(formatStr)) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(formatStr);
    return dateFormat.parse(dateString);
return null;
...
DatestringToDate(String dateString, String pattern)
string To Date
SimpleDateFormat simpledateformat = new SimpleDateFormat(pattern);
Date date = new Date();
try {
    date = simpledateformat.parse(dateString);
} catch (ParseException e) {
    e.printStackTrace();
return date;
...
DatestringToDate(String dateText, String format, boolean lenient)
string To Date
if (dateText == null) {
    return null;
DateFormat df = null;
try {
    if (format == null) {
        df = new SimpleDateFormat();
    } else {
...