List of utility methods to do Date String Parse
long | ISO8601ToTimestamp(String aDate) ISO To Timestamp long result = 0; SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ"); try { result = new Timestamp(format.parse(aDate).getTime()).getTime(); } catch (ParseException e) { e.printStackTrace(); return result; |
Date | ParseStringToDate(String date) Parse String To Date Date result = null; if (date != null && !date.equals("")) { String parse = date; parse = parse.replaceFirst("^[0-9]{4}([^0-9]?)", "yyyy$1"); parse = parse.replaceFirst("^[0-9]{2}([^0-9]?)", "yy$1"); parse = parse.replaceFirst("([^0-9]?)[0-9]{1,2}([^0-9]?)", "$1MM$2"); parse = parse.replaceFirst("([^0-9]?)[0-9]{1,2}( ?)", "$1dd$2"); ... |
Date | getDateByTime(String time) get Date By Time SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Date date; try { if (TextUtils.isEmpty(time)) { return null; date = sdf.parse(time); return date; ... |
boolean | isDateString(String dirtyDate) is Date String int len = dirtyDate.length(); if (len == 10) { for (int i = 0; i < len; i++) { if (i == 4 || i == 7) { if (dirtyDate.charAt(i) != '-') return false; } else { if (!Character.isDigit(dirtyDate.charAt(i))) ... |
boolean | isDateTimeString(String dirtyDateTime) is Date Time String int len = dirtyDateTime.length(); if (len != 10 && len != 19) return false; if (!isDateString(dirtyDateTime.substring(0, 10))) return false; if (len == 10) return true; if (dirtyDateTime.charAt(10) != ' ') ... |
Date | parse(String date) parse return parse(date, "yyyy-MM-dd"); |
Date | parse(String date, String format) parse DateFormat sdf = new SimpleDateFormat(format); try { return sdf.parse(date); } catch (ParseException e) { return null; |
Date | parse(String date, boolean isDateOnly) parse if (isDateOnly) { return parse(date); } else { return parse(date, "yyyy-MM-dd HH:mm"); |
Date | parse(String dateString, String dateFormat) parse if (StringUtil.isEmpty(dateString) || StringUtil.isEmpty(dateFormat)) { return null; SimpleDateFormat format = new SimpleDateFormat(dateFormat, Locale.ENGLISH); Date date = null; try { ... |
java.util.Date | parse(String src) parse try { return DateFormat.getDateInstance().parse(src); } catch (ParseException e) { return DateFormat.getInstance().getCalendar().getTime(); |