List of utility methods to do Date String Parse
Date | parseSimpleDate(String dateString) parse Simple Date SimpleDateFormat formatter = new SimpleDateFormat("DD/MM/yy", Locale.UK); Date date = null; try { date = (Date) formatter.parse(dateString); } catch (ParseException e) { e.printStackTrace(); return date; |
Date | parseUTCFormattedDateString(String dateString) parse UTC Formatted Date String SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm'Z'"); Date date = null; try { date = formatter.parse(dateString); } catch (ParseException e) { Log.e(DateTimeUtil.class.getSimpleName(), "Failed to parse date"); ... |
Date | parseYoutubeDate(String rawDate) parse Youtube Date final String TAG = "StringUtil.parseYoutubeDate"; String pattern = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US); String minusTimezone = rawDate.substring(0, rawDate.indexOf('.')); String cleanSpecials = minusTimezone.replace('T', ' '); try { return sdf.parse(cleanSpecials); } catch (ParseException pe) { ... |
Date | stringToDate(String str) string To Date if (isBlank(str)) { return null; try { return format.parse(str); } catch (ParseException e) { return null; |
Date | toDate(String sdate) to Date try { return dateFormater.parse(sdate); } catch (ParseException e) { try { return dateFormater.parse(new Date(toLong(sdate) * 1000L) .toGMTString()); } catch (ParseException e1) { return null; ... |
Date | toDate(String sdate) to Date try { return dateFormater.get().parse(sdate); } catch (ParseException e) { return null; |
String | toDateFormat(String d, String delim) to Date Format StringBuffer sb = new StringBuffer(); if (d == null || d.equals("") || d.length() != 8) { return d; sb.append(d.substring(0, 4)); sb.append(delim); sb.append(d.substring(4, 6)); sb.append(delim); ... |
Date | parseDate(CharSequence input) parse Date return parseDate(input, null);
|
Date | parseDate(CharSequence input, Date defaultDate) parse Date if (input == null) return defaultDate; else { try { return dateFormatter.parse(input.toString()); } catch (Exception e) { return null; |
Date | parseDate(CharSequence input, String pattern, Date defaultDate) parse Date if (input == null) return defaultDate; else { try { if (pattern != null) return new SimpleDateFormat(pattern).parse(input .toString()); else { ... |