Skip to content

Instantly share code, notes, and snippets.

@Ashusolanki
Last active March 28, 2019 13:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ashusolanki/fed3b6a680092985ac0ab93ed70fcd7c to your computer and use it in GitHub Desktop.
Save Ashusolanki/fed3b6a680092985ac0ab93ed70fcd7c to your computer and use it in GitHub Desktop.
private String postTime(Date date)
{
long postTime = date.getTime();
long atTime = System.currentTimeMillis();
long diff = atTime - postTime;
long sec = TimeUnit.SECONDS.convert(diff, TimeUnit.MILLISECONDS);
if (sec >= 60) {
long minit = TimeUnit.MINUTES.convert(diff, TimeUnit.MILLISECONDS);
if (minit >= 60) {
long hours = TimeUnit.HOURS.convert(diff, TimeUnit.MILLISECONDS);
if (hours >= 24) {
long days = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
return days + " Days Ago";
} else {
return hours + " Hours Ago";
}
} else {
return minit + " Minutes Ago";
}
} else {
return sec + " Secounds Ago";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment