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 strDate)
string To Date
DateFormat df = new SimpleDateFormat(DATE_FORMAT);
Date result = null;
if (!isBlank(strDate)) {
    result = df.parse(strDate);
return result;
DatestringToDate(String strDate)
Returns date that is represented by a string.
int[] diffTime = null;
boolean plusTime = true;
int idxT = strDate.indexOf('T');
if (idxT == -1) {
    throw new ParseException("Invalid Date Format", 0);
int idxDiffUTC = strDate.indexOf('-', idxT);
if (idxDiffUTC == -1) {
...
DatestringToDate(String strDate)
Convert String to Date with MM/dd/yyyy format.
Date date = new SimpleDateFormat("MM/dd/yyyy").parse(strDate);
return date;
DatestringToDate(String strDate)
string To Date
DateFormat df = new SimpleDateFormat(PATTERN);
Date date = df.parse(strDate);
return date;
DatestringToDate(String strDate, String formartStr)
string To Date
Date date = null;
if ((formartStr != null) && (!"".equals(formartStr))) {
    SimpleDateFormat sdf = new SimpleDateFormat(formartStr);
    try {
        date = sdf.parse(strDate);
    } catch (ParseException e) {
        date = null;
        e.printStackTrace();
...
DatestringToDate(String strDate, String oracleFormat)
string To Date
if (strDate == null)
    return null;
Hashtable h = new Hashtable();
String javaFormat = "";
String s = oracleFormat.toLowerCase();
if (s.indexOf("yyyy") != -1)
    h.put(new Integer(s.indexOf("yyyy")), "yyyy");
else if (s.indexOf("yy") != -1)
...
DatestringToDate(String strDate, String pattern)
string To Date
Date date = null;
DateFormat df = new SimpleDateFormat(pattern);
try {
    date = df.parse(strDate);
} catch (ParseException e) {
    return null;
return date;
...
DatestringToDate(String strDate, String strFormat)
This method parses the given string to the given date format
try {
    if (strDate == null || strDate.trim().equals(""))
        return null;
    String strDtFormat = "";
    strDtFormat = strFormat.toLowerCase();
    strDtFormat = replaceString(strDtFormat, "m", "M");
    if (strDtFormat.indexOf("hh:MM:ss") > 0)
        strDtFormat = replaceString(strDtFormat, "hh:MM:ss", "HH:mm:ss");
...
DatestringToDate(String string)
return date value of specified string value in format: yyyy-MM-dd HH:mm:ss
try {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return simpleDateFormat.parse(string);
} catch (Exception e) {
    return null;
DatestringToDate(String string, String format)
string To Date
Date dd = null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
try {
    dd = simpleDateFormat.parse(string.trim());
} catch (Exception e) {
    dd = null;
return dd;
...