Skip to content

Instantly share code, notes, and snippets.

@jcavar
Created May 11, 2014 15:16
Show Gist options
  • Save jcavar/5562962ad41f697df484 to your computer and use it in GitHub Desktop.
Save jcavar/5562962ad41f697df484 to your computer and use it in GitHub Desktop.
DateUtils getRelativeTimeSpanString method which cares about time zone
/**
* DateUtils getRelativeTimeSpanString methods which cares about time zone
* @param date date for which you want time ago
* @param timeZone time zone in which is date
* @return time ago string
*/
public static String timeAgoFromDate(Date date, TimeZone timeZone) {
TimeZone defaultTimeZone = TimeZone.getDefault();
TimeZone.setDefault(timeZone);
String relativeTimeSpan = DateUtils.getRelativeTimeSpanString(date.getTime()).toString();
TimeZone.setDefault(defaultTimeZone);
return relativeTimeSpan;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment