List of usage examples for android.text.format DateUtils getRelativeTimeSpanString
public static CharSequence getRelativeTimeSpanString(Context c, long millis, boolean withPreposition)
From source file:Main.java
public static CharSequence getCreatedAtString(long createdAt) { return DateUtils.getRelativeTimeSpanString(createdAt, System.currentTimeMillis(), 0); }
From source file:Main.java
public static String igFormattedDate(String timestamp) { /**// w w w . j av a 2s . c o m * From the group discussion board. */ CharSequence relativeDateTimeString = DateUtils.getRelativeTimeSpanString(Long.parseLong(timestamp) * 1000, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS); return relativeDateTimeString.toString().replaceAll("[^0-9]+", "s"); }
From source file:Main.java
public static String getTimeDiff(long otherTime) { long currentTime = Calendar.getInstance().getTimeInMillis(); String timeDiff = DateUtils.getRelativeTimeSpanString(otherTime, currentTime, DateUtils.MINUTE_IN_MILLIS) .toString();/*w w w . ja va2 s. co m*/ if (timeDiff.equals("0 minutes ago")) { return "<1 minute ago"; } return timeDiff; }
From source file:Main.java
public static String getRelativeTimeAgo(String rawJsonDate) { String twitterFormat = "EEE MMM dd HH:mm:ss ZZZZZ yyyy"; SimpleDateFormat sf = new SimpleDateFormat(twitterFormat, Locale.ENGLISH); sf.setLenient(true);/*from w ww . j a va2s . c o m*/ String relativeDate = ""; try { long dateMillis = sf.parse(rawJsonDate).getTime(); relativeDate = DateUtils .getRelativeTimeSpanString(dateMillis, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS) .toString(); } catch (ParseException e) { e.printStackTrace(); } // Shorten relative date relativeDate = relativeDate.replaceAll(" ", "").replace("seconds", "s").replace("second", "s") .replace("minutes", "m").replace("minute", "m").replace("hours", "h").replace("hour", "h") .replace("days", "d").replace("day", "d").replace("weeks", "w").replace("week", "w") .replace("months", "M").replace("month", "M").replace("years", "y").replace("year", "y") .replace("ago", "").replace("in", "").replace("0s", "just now"); return relativeDate; }
From source file:Main.java
public static String getRelativeTimeDiff(Date date) { String timeDiff = DateUtils .getRelativeTimeSpanString(date.getTime(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS) .toString();// ww w . j a v a 2s. c o m if (timeDiff.contains("0 ")) { timeDiff = "in few seconds ago"; } return timeDiff; }
From source file:Main.java
public static String getTimeString(Date fromdate) { long then;/*from w w w. j a va 2 s. c o m*/ then = fromdate.getTime(); Date date = new Date(then); StringBuffer dateStr = new StringBuffer(); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); Calendar now = Calendar.getInstance(); int days = daysBetween(calendar.getTime(), now.getTime()); int minutes = hoursBetween(calendar.getTime(), now.getTime()); int hours = minutes / 60; if (days == 0) { int second = minuteBetween(calendar.getTime(), now.getTime()); if (minutes > 60) { if (hours >= 1 && hours <= 24) { dateStr.append(hours).append("h"); } } else { if (second <= 10) { dateStr.append("Now"); } else if (second > 10 && second <= 30) { dateStr.append("few seconds ago"); } else if (second > 30 && second <= 60) { dateStr.append(second).append("s"); } else if (second >= 60 && minutes <= 60) { dateStr.append(minutes).append("m"); } } } else if (hours > 24 && days <= 7) { dateStr.append(days).append("d"); } else { dateStr.append(DateUtils.getRelativeTimeSpanString(date.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS)); } return dateStr.toString(); }
From source file:com.f2prateek.foodbot.model.LogAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { LogEntry entry = new LogEntry(cursor); TextView calories = (TextView) view.findViewById(R.id.tv_label_calories); TextView description = (TextView) view.findViewById(R.id.tv_label_description); TextView date = (TextView) view.findViewById(R.id.tv_label_timestamp); calories.setText(entry.getCalories() + ""); description.setText(entry.getDescription()); date.setText(DateUtils.getRelativeTimeSpanString(entry.getDate(), System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS));/*from ww w. j ava 2 s .c o m*/ }
From source file:com.samebits.beacon.locator.viewModel.BeaconViewModel.java
public String getSeenSince() { return DateUtils.getRelativeTimeSpanString(mManagedBeacon.getTimeLastSeen(), System.currentTimeMillis(), 0L) .toString(); }
From source file:ca.hoogit.garagepi.Utils.Helpers.java
/** * Create a relative from now time string * * @param timestamp Time since epoch/* w w w .j a v a 2s . co m*/ * @return Formatted string ie. "2 Minutes from now" */ public static String epochToFromNow(long timestamp) { return DateUtils .getRelativeTimeSpanString(timestamp, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS) .toString(); }
From source file:com.davidmiguel.gobees.hive.HiveInfoFragment.java
@Override public void showInfo(Hive hive) { // Last revision lastRevision.setText(DateUtils.getRelativeTimeSpanString(hive.getLastRevision().getTime(), (new Date()).getTime(), DateUtils.MINUTE_IN_MILLIS)); // Notes/*from w w w . j av a 2s . c om*/ if (Strings.isNullOrEmpty(hive.getNotes())) { notes.setText(getString(R.string.no_notes)); } else { notes.setText(hive.getNotes()); } }