Java Utililty Methods Date Format Guess

List of utility methods to do Date Format Guess

Description

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

Method

StringdetermineDateFormat(String dateString)
Determine SimpleDateFormat pattern matching with the given date string.
for (String regexp : DATE_FORMAT_REGEXPS.keySet()) {
    if (dateString.toLowerCase().matches(regexp)) {
        return DATE_FORMAT_REGEXPS.get(regexp);
return null; 
StringdetermineDateFormat(String dateString)
Determine SimpleDateFormat pattern matching with the given date string.
for (String regexp : DATE_FORMAT_REGEXPS.keySet()) {
    if (dateString.toLowerCase().matches(regexp)) {
        return DATE_FORMAT_REGEXPS.get(regexp);
return null; 
StringdetermineDateFormat(String dateString)
Determine SimpleDateFormat pattern matching with the given date string.
for (String regexp : DATE_FORMAT_REGEXPS.keySet())
    if (dateString.toLowerCase().matches(regexp))
        return DATE_FORMAT_REGEXPS.get(regexp);
throw new ParseException("unable to parse date", 0);
DategetDateFormat(Date date)
Date Format yyyy-MM-dd HH:mm:ss
SimpleDateFormat df = new SimpleDateFormat(simple);
try {
    return df.parse(df.format(date));
} catch (ParseException e) {
    e.printStackTrace();
return date;
StringgetDateFormat(Date date, String format)
get Date Format
String strDateTime = "";
DateFormat df = new SimpleDateFormat(format);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
strDateTime = df.format(date);
return strDateTime;
StringgetDateFormat(String date)
Retrieves the date pattern.
if (date == null || date.equals("")) {
    return null;
SimpleDateFormat dateFormat = new SimpleDateFormat();
String[] patterns = new String[] { "yyyyMMdd'T'HHmmss'Z'", "yyyyMMdd'T'HHmmss", "yyyyMMdd", "yyyy-MM-dd" };
int[] patternsLength = new int[] { 16, 15, 8, 10 };
int s = patterns.length;
Date d = null;
...
StringgetDateFormat(String date)
Get the date pattern
if (date == null || date.equals("")) {
    return null;
SimpleDateFormat dateFormat = new SimpleDateFormat();
String[] patterns = new String[] { PATTERN_UTC, PATTERN_UTC_WOZ, PATTERN_UTC_WSEP, PATTERN_YYYY_MM_DD,
        PATTERN_YYYYMMDD, PATTERN_LOCALTIME, PATTERN_LOCALTIME_WOT, PATTERN_YYYY_MM_DD_HH_MM_SS };
int[] patternsLength = new int[] { PATTERN_UTC_LENGTH, PATTERN_UTC_WOZ_LENGTH, PATTERN_UTC_WSEP_LENGTH,
        PATTERN_YYYY_MM_DD_LENGTH, PATTERN_YYYYMMDD_LENGTH, PATTERN_LOCALTIME_LENGTH,
...
DateFormatgetDateFormat(String date)
get Date Format
Matcher dateMatcher = dateRegex.matcher(date);
if (dateMatcher.matches()) {
    return new SimpleDateFormat(DATE_FORMAT);
Matcher timeMatcher = timeRegex.matcher(date);
if (timeMatcher.matches()) {
    return new SimpleDateFormat(TIME_FORMAT);
return new SimpleDateFormat(DATE_TIME_FORMAT);
DateFormatgetDateFormat(String dateStr)
get Date Format
int pos1 = dateStr.indexOf("-");
int pos2 = dateStr.indexOf(":");
DateFormat dt = null;
if (pos1 != -1 && pos2 != -1) {
    dt = fmtDT;
} else if (pos1 != -1 && pos2 == -1) {
    dt = fmtDate;
} else if (pos1 == -1 && pos2 != -1) {
...
StringgetDateFormatted(Date date)
Extraer fecha formateada
return getDateFormatted(date, "dd/MM/yyyy");