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

DatestringToDateForIng(String date_str)
string To Date For Ing
SimpleDateFormat format = new SimpleDateFormat(datePatternForIng);
try {
    return format.parse(date_str);
} catch (ParseException e) {
    throw new Exception("errors.date.invalid");
DateStringToDateFormat(String str, String format)
String To Date Format
Date dt = new Date();
if (str != null && !str.equals("")) {
    SimpleDateFormat transFormat = new SimpleDateFormat(format);
    dt = transFormat.parse(str);
return dt;
DatestringToDateInTimeZone(String time, String timeZone)
string To Date In Time Zone
SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMddHHmm");
dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
Date d = null;
try {
    d = dateFormat.parse(time);
} catch (ParseException e) {
    e.printStackTrace();
return d;
DatestringToDateMetaData(String dateString)
String to date meta data.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.S");
try {
    return sdf.parse(dateString);
} catch (NullPointerException ex) {
    return null;
} catch (ParseException ex) {
    return null;
DatestringToDateTemporalCoverage(String dateString)
string To Date Temporal Coverage
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
    return sdf.parse(dateString);
} catch (NullPointerException ex) {
    return null;
} catch (ParseException ex) {
    return null;
DatestringToDatetime(String str, String format)
string To Datetime
if (str == null || str.equals(""))
    return null;
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
    return sdf.parse(str);
} catch (ParseException e) {
    e.printStackTrace();
    return null;
...
DatestringToDatetime(String string)
string To Datetime
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dateTime = dateFormat.parse(string);
return dateTime;
DatestringToDateTime(String stringDate, String format)
string To Date Time
if (stringDate == null) {
    return null;
try {
    return getFormat(format).parse(stringDate);
} catch (ParseException e) {
    throw new RuntimeException(e);
DatestringToDateWithFormat(String stringToConvert, String dateFormat)
string To Date With Format
if (stringToConvert != null) {
    try {
        DateFormat simpleDateFormat = new SimpleDateFormat(dateFormat);
        Date date = simpleDateFormat.parse(stringToConvert);
        return date;
    } catch (ParseException e) {
return new Date(0);
DatestrMSShortToDate(String str_date)
str MS Short To Date
try {
    return (Date) formatterMSShort.parse(str_date);
} catch (Exception e) {
    System.out.println("StrToDateSSShort Exception :" + e + " " + str_date);
    return null;