List of utility methods to do Date Relative Format
String | formatRelativeTime(String fullRelativeDate) format Relative Time final String relativeDateFormat1 = "(\\d+)\\s(\\w+)\\s\\w+"; final Pattern relativeDatePattern1 = Pattern .compile(relativeDateFormat1); final String relativeDateFormat2 = "(\\w+)\\s(\\d+)\\s(\\w+)"; final Pattern relativeDatePattern2 = Pattern .compile(relativeDateFormat2); final Matcher matcher1 = relativeDatePattern1 .matcher(fullRelativeDate); ... |
String | getRelativeTimeofTweet(String tweetCreatedAt) get Relative Timeof Tweet final SimpleDateFormat sdf = new SimpleDateFormat( TWITTER_TIMESTAMP_FORMAT, Locale.ENGLISH); String relativeTime = ""; try { long dateInMillis = sdf.parse(tweetCreatedAt).getTime(); relativeTime = getRelativeTimeFromMilliSeconds(dateInMillis); } catch (ParseException e) { Log.d("info", "Couldn't parse relative timestamp for: " ... |
String | relativeDate(String dateString) relative Date String dayMonthYear = dateString.substring(0, dateString.indexOf(" ")); int month = Integer.parseInt(dayMonthYear.substring(0, 2)); int day = Integer.parseInt(dayMonthYear.substring(3, 5)); int year = Integer.parseInt(dayMonthYear.substring(6, 8)); Calendar cal = Calendar.getInstance(); int currentDay = cal.get(Calendar.DAY_OF_MONTH); int currentMonth = cal.get(Calendar.MONTH) + 1; ... |
String | getRelativeDate(Date date) get Relative Date return DateUtils.getRelativeTimeSpanString(date.getTime(), new Date().getTime(), DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString(); |
String | humanFriendlyDate(Date date) human Friendly Date return humanFriendlyDate(date.getTime());
|
boolean | dateIsBetweenTwoDates(String begin, String end) date Is Between Two Dates String[] splitBeginStr = begin.split(":"); int hrBegin = Integer.parseInt(splitBeginStr[0]); int minBegin = Integer.parseInt(splitBeginStr[1]); String[] splitEndStr = end.split(":"); int hrEnd = Integer.parseInt(splitEndStr[0]); int minEnd = Integer.parseInt(splitEndStr[1]); Calendar beginCal = Calendar.getInstance(); beginCal.set(Calendar.HOUR_OF_DAY, hrBegin); ... |
String | getHumanReadableDateDiff(Date pastDate, boolean unknownIfNull) Returns some kind of human readable representation of a past date, e.g. if (pastDate == null || pastDate.getTime() == 0) { return unknownIfNull ? "Unknown" : "Never"; Date currentDate = new Date(); long timeDiff = currentDate.getTime() - pastDate.getTime(); if (timeDiff < TimeUnit.SECONDS.toMillis(60)) { return "<1 min ago"; } else if (timeDiff < TimeUnit.SECONDS.toMillis(60 * 60)) { ... |