Java Utililty Methods Parse Date

List of utility methods to do Parse Date

Description

The list of methods to do Parse Date are organized into topic(s).

Method

DateparseDate(String dateStr)
parse Date
try {
    if (isValidDateString(dateStr)) {
        return (new SimpleDateFormat(DATE_FORMAT).parse(dateStr));
    } else if (dateStr.indexOf("T") > 0) {
        return (new SimpleDateFormat(DATE_FORMAT).parse(dateStr.substring(0, dateStr.indexOf('T'))));
    } else {
        return (new SimpleDateFormat(DATE_FORMAT).parse(dateStr.substring(0, dateStr.indexOf(" "))));
} catch (ParseException e) {
    throw new IllegalArgumentException("Invalid date format: " + dateStr, e);
DateparseDate(String dateStr)
parse Date
return parseDate(dateStr, "yyyy-MM-dd");
DateparseDate(String datestr)
parse Date
if (null == datestr || "".equals(datestr)) {
    return null;
try {
    String fmtstr = null;
    if (datestr.contains(":") && datestr.contains("-")) {
        fmtstr = "yyyy-MM-dd HH:mm:ss";
    } else if (datestr.contains(":") && datestr.contains("/")) {
...
DateparseDate(String dateStr, SimpleDateFormat... formats)
parse Date
for (SimpleDateFormat sdf : formats) {
    try {
        return sdf.parse(dateStr);
    } catch (ParseException ignored) {
return null;
DateparseDate(String dateStr, String dateFormat)
Parse the date in string format based on date format and return a Date object
DateFormat format = new SimpleDateFormat(dateFormat);
return format.parse(dateStr);
DateparseDate(String dateStr, String dateFormat)
parse Date
return new SimpleDateFormat(dateFormat).parse(dateStr);
DateparseDate(String dateStr, String format)
Parse the date with the given date string and date format.
if (isNullOrEmpty(format) || isNullOrEmpty(dateStr)) {
    return null;
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.parse(dateStr.trim());
DateparseDate(String dateStr, String format)
parse Date
if (dateStr == null)
    return null;
SimpleDateFormat formatter = new SimpleDateFormat(format);
ParsePosition ps = new ParsePosition(0);
Date date = formatter.parse(dateStr, ps);
return date;
DateparseDate(String dateStr, String... formats)
Parses a string into Date using the SimpleDateFormat format string provided.
return parseDate(dateStr, null, formats);
DateparseDate(String dateString)
parse Date
return parseDate(dateString, Locale.getDefault(), TimeZone.getDefault());