Last active
March 28, 2019 13:21
-
-
Save Ashusolanki/fed3b6a680092985ac0ab93ed70fcd7c to your computer and use it in GitHub Desktop.
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
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