-
-
Save nesquena/f786232f5ef72f6e10a7 to your computer and use it in GitHub Desktop.
Code for parsing a relative twitter date
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
// getRelativeTimeAgo("Mon Apr 01 21:16:23 +0000 2014"); | |
public String getRelativeTimeAgo(String rawJsonDate) { | |
String twitterFormat = "EEE MMM dd HH:mm:ss ZZZZZ yyyy"; | |
SimpleDateFormat sf = new SimpleDateFormat(twitterFormat, Locale.ENGLISH); | |
sf.setLenient(true); | |
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(); | |
} | |
return relativeDate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or, to use abbreviations like "5m" and "3d" instead of "5 minutes ago" and "3 days ago", check this out: