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

CalendarparseDateTime(String fullDateParam, String unixDateParam, Map request)
Parses datetime (firstly formated by DATE_FORMAT then unix format).
String[] fullDateStrArr = request.get(fullDateParam);
if (fullDateStrArr != null && fullDateStrArr.length == 1) {
    String dateStr = fullDateStrArr[0];
    return parseFullDate(fullDateParam, dateStr);
String[] unixDateStrArr = request.get(unixDateParam);
if (unixDateStrArr != null && unixDateStrArr.length == 1) {
    String dateStr = unixDateStrArr[0];
...
longparseDateTime(String s)
Parses a date from a string.
DateFormat df = null;
for (int i = 0; true; ++i) {
    switch (i) {
    case 0:
        df = new java.text.SimpleDateFormat("MMM d, yyyy K:m:s a", java.util.Locale.ENGLISH);
        break;
    case 1:
        df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, java.util.Locale.ENGLISH);
...
DateparseDateTime(String s)
parse Date Time
if (s == null || s.length() == 0)
    return null;
for (DateFormat dateFormat : dateTimeParsers) {
    try {
        Date res = dateFormat.parse(s);
        return res;
    } catch (Exception e) {
return null;
DateparseDateTime(String s)
Converts a date in the form of "yy-MM-dd HH:mm:ss" to a Date object using the default time zone.
return parseDateTime(s, null);
CalendarparseDateTime(String s)
Parses the date/time stamp from a given input parameter using one of the following formats
  • mm/dd/yyyy
  • mm/dd/yyyy hh:mm:ss
  • EEE MMM dd HH:mm:ss zzz yyyy - this is the standard output from the unix date command
  • EEE mm/dd/yyyy HH:mm:ss.ms - this is the standard output from the windows command echo %date% %time%
  • yyyy-MM-ddThh:mm:ss.zzzzzzz
  • Epoch time (ms)
  • PnYnMnDTnHnMnS - XML lexical representation
SimpleDateFormat f1 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat f2 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
SimpleDateFormat f3 = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
SimpleDateFormat f4 = new SimpleDateFormat("EEE MM/dd/yyyy HH:mm:ss.ms");
SimpleDateFormat f5 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.zzzzzzz");
Date d = null;
try {
    d = f1.parse(s, new ParsePosition(0));
...
DateparseDatetime(String value)
parse Datetime
try {
    return DATETIME_FORMATTER.parse(value);
} catch (ParseException e) {
    throw new RuntimeException("Cannot parse " + value);
DateparseDateTimeFromString(String datetime)
parse Date Time From String
Date date = tryToParse(datetime, RFC_822_DATE_FORMAT.get());
if (date == null) {
    date = tryToParse(datetime, RFC_850_DATE_FORMAT.get());
if (date == null) {
    date = tryToParse(datetime, ANSI_DATE_FORMAT.get());
return date;
...
DateparseDateTimeHuman(String dateString)
parse Date Time Human
DateFormat df = new SimpleDateFormat(DATE_TIME_PATTERN_HUMAN);
Date date;
try {
    date = df.parse(dateString);
} catch (ParseException e) {
    date = new Date();
return date;
...
LongparseDateTimeString(final String date)
parse Date Time String
if (NULL.equals(date) || date == null || date.length() == 0) {
    return null;
String tmp = date.replace('T', ' ');
tmp = tmp.replaceAll("#", ":");
tmp = tmp.replaceAll(FILE_MILLISECOND_SEPERATOR, ".");
tmp = tmp.replace("Z", " +0000");
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS zzz");
...
StringparseDateTimeString(String dateTime)
Parse time stamp from elfcloud.fi server
if (dateTime == null || dateTime.length() == 0) {
    return "";
Calendar c = Calendar.getInstance();
TimeZone z = c.getTimeZone();
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
inputFormat.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm Z");
...