Skip to content

Instantly share code, notes, and snippets.

@gauravrai1
Created January 7, 2018 16:51
Show Gist options
  • Save gauravrai1/24e84982351ca29cf957d00a9f064f5d to your computer and use it in GitHub Desktop.
Save gauravrai1/24e84982351ca29cf957d00a9f064f5d to your computer and use it in GitHub Desktop.
String timeStamp = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + "";
long posttime = Long.parseLong( list_items.getTime());
long nowtime = Long.parseLong(timeStamp);
long diff = nowtime - posttime;
int diffe = (int) diff;
if (diffe<60) {
String time = String.valueOf(diff);
holder.date.setText(time+"s ago");
} else if (diffe> 60 && diffe<3600) {
diff = diff/60;
String time = String.valueOf(diff);
holder.date.setText(time+"m ago");
} else if (diffe> 3600 && diffe<86400) {
diff = diff/3600;
String time = String.valueOf(diff);
holder.date.setText(time+"h ago");
} else if (diffe>86400) {
diff = diff/86400;
String time = String.valueOf(diff);
holder.date.setText(time+"d ago");
} else if (diffe == 60) {
holder.date.setText("1m ago");
} else if (diffe == 3600) {
holder.date.setText("1h ago");
} else if (diffe == 86400) {
holder.date.setText("1d ago");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment