List of utility methods to do Regex Date Vaidate
Date | parseDate(String date) parse Date if (date == null || date.length() == 0) { return null; Pattern pattern = Pattern.compile( "(\\d{4})(?:-(\\d{2}))?(?:-(\\d{2}))?(?:([Tt])?(?:(\\d{2}))?(?::(\\d{2}))?(?::(\\d{2}))?(?:\\.(\\d{3}))?)?([Zz])?(?:([+-])(\\d{2}):(\\d{2}))?"); Matcher m = pattern.matcher(date); if (m.find()) { if (m.group(4) == null) ... |
Calendar | parseDate(String dateStr) parse Date Calendar cal = parseUTCDate(dateStr); if (cal == null) cal = parseUTCFuncDate(dateStr); return cal; |
String | parseDate(String entry) parse Date Pattern pattern = Pattern.compile(DATE_REGEX_4_DIGIT_YEAR); String[] terms = entry.split(" "); Matcher matcher; for (String term : terms) { matcher = pattern.matcher(term); while (matcher.matches()) { return matcher.group(); pattern = Pattern.compile(DATE_REGEX_2_DIGIT_YEAR); terms = entry.split(" "); for (String term : terms) { matcher = pattern.matcher(term); while (matcher.matches()) { return matcher.group(); return ""; |
String | parseDate(String text) parse Date String regex = "(\\d{4}[-|\\/]\\d{1,2}[-|\\/]\\d{1,2})"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(text); while (m.find()) { return m.group(); return ""; |
long | parseDateDiff(final String time) parse Date Diff try { final Pattern timePattern = Pattern.compile( "(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)?", 2); final Matcher m = timePattern.matcher(time); int years = 0; int months = 0; int weeks = 0; ... |
long | parseDateDiff(String time) parse Date Diff try { Long mil = 999L; Matcher matcher = Pattern.compile("\\d+\\D+").matcher(time); while (matcher.find()) { String s = matcher.group(); Long numb = Long.parseLong(s.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)")[0]); String type = s.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)")[1]; switch (type) { ... |
long | parseDateDiff(String time, boolean future) parse Date Diff Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE); Matcher m = timePattern.matcher(time); int hours = 0; int minutes = 0; int seconds = 0; ... |
Date | parseDateOffset(String time) parse Date Offset Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE); Matcher m = timePattern.matcher(time); int years = 0; int months = 0; int weeks = 0; ... |