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 date)
String to date.
Date formattedDate = null;
try {
    SimpleDateFormat sd = new SimpleDateFormat("dd/MM/yyyy");
    formattedDate = sd.parse(date);
} catch (ParseException e) {
    System.out.println("<<<<error >>>>" + e.getMessage());
    e.printStackTrace();
return formattedDate;
DatestringToDate(String date)
string To Date
try {
    TimeZone tz = TimeZone.getDefault();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
    sdf.setTimeZone(tz);
    return sdf.parse(date);
} catch (ParseException ex) {
    return null;
DatestringToDate(String date)
string To Date
Integer day = Integer.valueOf(date.split("/")[0]);
String corectedDate = String.valueOf(day + 1) + "/" + date.split("/")[1] + "/" + date.split("/")[2];
SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
Date fechaDate = null;
try {
    fechaDate = formato.parse(corectedDate);
} catch (ParseException ex) {
return fechaDate;
DatestringToDate(String date)
Parse a String date into a Date object.
if (date == null) {
    return null;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("GMT-0"));
return format.parse(date);
DateTimestringToDate(String date)
string To Date
return DateTime.parse(date, magisterToDateFormatter).withZone(DateTimeZone.getDefault());
DateStringToDate(String date)
String To Date
try {
    return yyyyMMdd.parse(date);
} catch (ParseException e) {
return new Date();
DatestringToDate(String date)
string To Date
SimpleDateFormat sdf = new SimpleDateFormat(DATE_PARTTEN);
Date d = null;
try {
    String[] datesl = new String[3];
    if (date.contains("-")) {
        datesl = date.split("-");
    } else if (date.contains("/")) {
        datesl = date.split("/");
...
DatestringToDate(String date)
string To Date
if (date == null) {
    return null;
String separator = String.valueOf(date.charAt(4));
String pattern = "yyyyMMdd";
if (!separator.matches("\\d*")) {
    pattern = "yyyy" + separator + "MM" + separator + "dd";
    if (date.length() < 10) {
...
DatestringToDate(String date, String format)
string To Date
Date d = null;
try {
    SimpleDateFormat formatter = new SimpleDateFormat(format);
    d = formatter.parse(date);
    if (!formatter.format(d).equals(date)) {
        throw new Exception("error format date");
} catch (ParseException e) {
...
DatestringToDate(String date, String pattren)
string To Date
if (date == null || date.trim().isEmpty())
    return null;
if (pattren != null && !pattren.trim().isEmpty()) {
    DateFormat formater = new SimpleDateFormat(pattren);
    try {
        return formater.parse(date);
    } catch (Exception e) {
        e.printStackTrace();
...