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 Expression)
String To Date
return StringToDate(Expression, defaultPattern);
DateStringToDate(String fecha)
String To Date
SimpleDateFormat formatoDelTexto = new SimpleDateFormat("yyyy/MM/dd");
Date aux = null;
try {
    aux = formatoDelTexto.parse(fecha);
} catch (Exception ex) {
return aux;
DatestringToDate(String fecha, String formato)
string To Date
fecha = nullToBlank(fecha);
GregorianCalendar gc = new GregorianCalendar();
SimpleDateFormat df = new SimpleDateFormat(formato);
try {
    gc.setTime(df.parse(fecha));
    return gc.getTime();
} catch (ParseException e) {
    System.out.println("Error con fecha: " + e.getMessage());
...
DateStringToDate(String format, String dateStr)
String To Date
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
try {
    Date date = dateFormat.parse(dateStr.trim());
    return date;
} catch (Exception e) {
    e.printStackTrace();
return null;
...
DatestringToDate(String input)
string To Date
Date date = null;
String dateFormat = getDateFormat(input);
if (dateFormat == null) {
    throw new IllegalArgumentException("Date is not in an accepted format " + input);
for (String sep : dateSeparators) {
    String actualDateFormat = patternForSeparator(dateFormat, sep);
    for (String time : timeFormats) {
...
java.util.DatestringToDate(String pstrValue, String pstrDateFormat)
Convert string to Date
if ((pstrValue == null) || (pstrValue.equals(""))) {
    return null;
java.util.Date dttDate = null;
try {
    SimpleDateFormat oFormatter = new SimpleDateFormat(pstrDateFormat);
    dttDate = oFormatter.parse(pstrValue);
    oFormatter = null;
...
DatestringToDate(String s)
string To Date
SimpleDateFormat sd = new SimpleDateFormat(DATE_FORMAT);
Date date = sd.parse(s);
return date;
DateStringToDate(String s)
String To Date
Date date = new Date();
try {
    SimpleDateFormat simpledateformat = new SimpleDateFormat(PATTERN_YMDHMS);
    ParsePosition parseposition = new ParsePosition(0);
    date = simpledateformat.parse(s, parseposition);
} catch (Exception ex) {
return date;
...
DatestringToDate(String s)
string To Date
if (s == null)
    return null;
try {
    return _df.parse(s);
} catch (Exception e) {
    return null;
DateStringToDate(String s)
String To Date
return StringToDate(s, "yyyy-MM-dd hh:mm:ss");