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

DatetoDate(String dateString, String dateFormatPattern)
Converts a String to a Date, using the specified pattern.
Date date = null;
if (dateFormatPattern == null) {
    dateFormatPattern = "yyyy-MM-dd";
synchronized (dateFormat) {
    dateFormat.applyPattern(dateFormatPattern);
    dateFormat.setLenient(false);
    date = dateFormat.parse(dateString);
...
DatetoDate(String dateString, String format)
to Date
try {
    DateFormat fmt = new SimpleDateFormat(format);
    return fmt.parse(dateString);
} catch (ParseException e) {
    return null;
DatetoDate(String datetime)
to Date
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
    return sdf.parse(datetime);
} catch (ParseException e) {
    return EPOCH;
DatetoDate(String dateToConvert)
This function takes a timezone string and converts it to a Java Date
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date date = formatter.parse(dateToConvert);
return date;
DatetoDate(String dateToDatify)
Creer une date GMT
try {
    return sdf.parse(dateToDatify);
} catch (ParseException e) {
    return null;
DatetoDate(String dateValue, String format)
to Date
Date value = null;
try {
    value = newDateFormat(format).parse(dateValue);
} catch (Exception e) {
return value;
DatetoDate(String format, String str)
to Date
Date date = null;
if (format == null) {
    sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
} else {
    sdf.applyPattern(format);
try {
    date = sdf.parse(str);
...
DatetoDate(String formatDate, String stringDate)
to Date
if (stringDate == null || stringDate.isEmpty()) {
    return null;
SimpleDateFormat format = new SimpleDateFormat(formatDate);
return format.parse(stringDate);
DatetoDate(String param)
to Date
Date date = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
    date = sdf.parse(param);
} catch (ParseException ex) {
return date;
DatetoDate(String patten, String value)
To date.
DateFormat formater = new SimpleDateFormat(patten);
try {
    return formater.parse(value);
} catch (ParseException e) {
    throw new IllegalArgumentException(e);