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(final String date, final String format)
Parse string to date using given format.
final SimpleDateFormat dfmt = new SimpleDateFormat(format);
return dfmt.parse(date);
DateparseDate(final String dateStr)
Attempts to parse given date string using patterns described https://tools.ietf.org/html/rfc6991#page-11 with exception that ONLY UTC patterns are accepted.
for (final String fmt : DATE_AND_TIME_FORMATS) {
    try {
        final SimpleDateFormat sdf = new SimpleDateFormat(fmt);
        sdf.setTimeZone(TZ_UTC);
        return sdf.parse(dateStr);
    } catch (ParseException e) {
throw new IllegalArgumentException(
        "Unrecognized DateAndTime value : " + dateStr + " (only UTC date is accepted)");
DateparseDate(final String dateString)
This method parses a Date from a string with the format dd.MM.yyyy kk:mm.
Date date = null;
DateFormat formatter;
try {
    formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    date = formatter.parse(dateString);
} catch (final ParseException d) {
    try {
        formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
...
DateparseDate(final String pDate)
Parse the given date using the #OCCURRENCE_DATE_FORMAT format.
final SimpleDateFormat format = new SimpleDateFormat(OCCURRENCE_DATE_FORMAT);
return format.parse(pDate);
DateparseDate(final String revision)
parse Date
final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
    return formatter.parse(revision);
} catch (final ParseException e) {
    throw new IllegalArgumentException("Date not valid", e);
DateparseDate(final String source)
Parse the Date using pattern "yyyy-MM-dd"
if (source == null || source.trim().length() == 0) {
    return null;
return dateFormat.parse(source);
DateparseDate(final String source)
parse Date
return dateFormat.get().parse(source);
DateparseDate(final String str)

Parses a string representing a date by trying different date patterns.

The following date patterns are tried (in the given order):

"yyyy-MM-dd", "yyyy/MM/dd", "yyyyMMdd", "yyyy", "dd.MM.yyyy", "dd MMM yyyy", "dd MMM. 
if ("today".equalsIgnoreCase(str) || "now".equalsIgnoreCase(str)) {
    return new Date();
for (int i = 0; i < DATE_PATTERNS.length; i++) {
    DATE_PARSER.applyPattern(DATE_PATTERNS[i]);
    DATE_PARSE_POSITION.setIndex(0);
    final Date date = DATE_PARSER.parse(str, DATE_PARSE_POSITION);
    if (date != null && DATE_PARSE_POSITION.getIndex() == str.length()) {
...
DateparseDate(final String str, final Locale locale, final String... parsePatterns)
parse Date
return parseDateWithLeniency(str, locale, parsePatterns, true);
DateparseDate(final String value)
parse Date
try {
    return getUtilDateFormat().parse(value);
} catch (ParseException e) {
    return throwRuntimeParseException(value, e);