Java Utililty Methods Date Parse

List of utility methods to do Date Parse

Description

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

Method

longdateFromFilename(File file, Pattern fileNamePattern, DateFormat dateFormat)
Returns the date embedded in the given file name as milliseconds since the epoch.
long utc = 0;
Matcher m = fileNamePattern.matcher(file.getName());
if (m.matches()) {
    utc = dateFormat.parse(m.group(1), new ParsePosition(0)).getTime();
return utc;
DatedateFromHourAndMinutes(final String pTime)
Generate from a date object from a given date-string (HH:mm), like 12:13
final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
return sdf.parse(pTime);
DatedateFromISO8601(String iso)
date From ISO
try {
    String noColon = iso.substring(0, 26) + iso.substring(27);
    return tportResultFormat.parse(noColon);
} catch (ParseException e) {
    throw new RuntimeException("Really unlikely, but it looks like "
            + "travelport is not using ISO dates anymore! " + e.getMessage());
DatedateFromISO8601(String time)
date From ISO
if (time.length() < 6) {
    return new Date(0);
try {
    if (time.endsWith("Z")) {
        time = time.substring(0, time.length() - 1) + "GMT-00:00";
    } else {
        time = time.substring(0, time.length() - 6) + "GMT"
...
DatedateFromISODate(String isoDate)
date From ISO Date
TimeZone tz = TimeZone.getTimeZone("UTC");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
dateFormat.setTimeZone(tz);
try {
    return dateFormat.parse(isoDate);
} catch (ParseException e) {
    return null;
java.util.DatedateFromString(final String value)
Parses string into a Date object, first attempting as long(millis) then using the SimpleDateFormat: "MM-dd-yyyy"
java.util.Date d = null;
try {
    d = new java.util.Date();
    d.setTime(Long.parseLong(value));
} catch (NumberFormatException nfe) {
    try {
        d = new SimpleDateFormat("MM-dd-yyyy").parse(value);
    } catch (ParseException e) {
...
DatedateFromString(String date)
Parse String to Date object.
try {
    return formatter.parse(date);
} catch (ParseException e) {
    return null;
DatedateFromString(String date, String pattern)
Convert date string with pattern to date
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
try {
    return formatter.parse(date);
} catch (Throwable ex) {
    throw new RuntimeException("The date string " + date + " is not in an expected format");
DatedateFromString(String dateString)
date From String
try {
    return new SimpleDateFormat("dd.MM.yyyy").parse(dateString);
} catch (ParseException e) {
    throw new RuntimeException(e);
DatedateFromString(String dateString)
New date for the given string based on format date
Date date = null;
try {
    date = dateFormat.parse(dateString);
} catch (ParseException pe) {
return date;