Created
May 11, 2014 15:16
-
-
Save jcavar/5562962ad41f697df484 to your computer and use it in GitHub Desktop.
DateUtils getRelativeTimeSpanString method which cares about time zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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