List of utility methods to do Date Parse
long | dateFromFilename(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; |
Date | dateFromHourAndMinutes(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); |
Date | dateFromISO8601(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()); |
Date | dateFromISO8601(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" ... |
Date | dateFromISODate(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.Date | dateFromString(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) { ... |
Date | dateFromString(String date) Parse String to Date object. try { return formatter.parse(date); } catch (ParseException e) { return null; |
Date | dateFromString(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"); |
Date | dateFromString(String dateString) date From String try { return new SimpleDateFormat("dd.MM.yyyy").parse(dateString); } catch (ParseException e) { throw new RuntimeException(e); |
Date | dateFromString(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; |