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

DatestringDateToDate(String str)
string Date To Date
java.text.DateFormat format = new java.text.SimpleDateFormat("yyyyMMdd");
return format.parse(str);
DatestringDateToDate(String StrDate)
string Date To Date
Date dateToReturn = null;
SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT);
try {
    dateToReturn = (Date) dateFormat.parse(StrDate);
} catch (ParseException e) {
    e.printStackTrace();
return dateToReturn;
...
DatestringFechaToDate(String fechaS)
Convierte una fecha almacenada en una hilera de caracteres, con formato dd/MM/yyyy a un objeto de tipo date
SimpleDateFormat formateador = new SimpleDateFormat("dd/MM/yyyy");
try {
    return formateador.parse(fechaS);
} catch (ParseException pe) {
    return null;
DatestringToDate(final String dateString)
string To Date
Date ret = null;
for (final String format : formats) {
    try {
        final SimpleDateFormat frm = new SimpleDateFormat(format);
        ret = frm.parse(dateString);
        break;
    } catch (final ParseException e) {
        continue;
...
DatestringToDate(final String dateTimeStr)
Transformiert einen HL7 Date/Time String in ein java.util.Date
if (dateTimeStr == null || dateTimeStr.length() == 0) {
    return null;
if (dateTimeStr.length() >= 14) {
    SimpleDateFormat sdf = new SimpleDateFormat(DTM_DATE_TIME_PATTERN.substring(0, 14));
    return sdf.parse(dateTimeStr);
} else {
    SimpleDateFormat sdf = new SimpleDateFormat(DTM_DATE_TIME_PATTERN.substring(0, dateTimeStr.length()));
...
DatestringToDate(final String str, final String dateFormat)
string To Date
return stringToDate(str, dateFormat, Locale.getDefault());
DatestringToDate(final String string, final String format)
parse the string to date
return stringToDate(string, format, null);
DateStringToDate(String data)
String To Date
if (data == null || data.equals("")) {
    return null;
Date date = null;
try {
    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm");
    date = (java.util.Date) formatter.parse(data);
} catch (ParseException e) {
...
DatestringToDate(String data)
string To Date
Date retorno = new Date();
;
if (data != null && !data.equalsIgnoreCase("")) {
    try {
        retorno = format.parse(data);
    } catch (ParseException e) {
        e.printStackTrace();
} else {
    retorno = null;
return retorno;
DatestringToDate(String date)
Formats a date given as a string in a stringobject allowed dates are

"yyyy/MM/dd HH:mm" "yyyy-MM-dd HH:mm" "yyyy/MM/dd" "yyyy-MM-dd"

String pattern;
if (date.contains("/") && date.contains(":")) {
    pattern = "yyyy/MM/dd HH:mm";
} else if (date.contains("/") && !date.contains(":")) {
    pattern = "yyyy/MM/dd";
} else if (date.contains("-") && date.contains(":")) {
    pattern = "yyyy-MM-dd HH:mm";
} else if (date.contains("-") && !date.contains(":")) {
...