Created
June 2, 2016 11:11
-
-
Save riyazMuhammad/5dc8271fb4986adb8878a9cdac93ada7 to your computer and use it in GitHub Desktop.
days spent
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
/** | |
* @param fromDate | |
* @return | |
*/ | |
public static String getDateDiffPastInDays(Long fromDate) { | |
Date currentDate = new Date(); | |
if (currentDate.getTime() <= fromDate) { | |
return ""; | |
} else { | |
long days = TimeUnit.MILLISECONDS.toDays(new Date().getTime() - fromDate); | |
if (days > 365) { | |
return days / 365 + (days / 365 > 1 ? " years ago" : " year ago"); | |
} else if (days > 30) { | |
return days / 30 + (days / 30 > 1 ? " months ago" : " month ago"); | |
} else { | |
if (days == 0) { | |
return "Today"; | |
} else { | |
return days + (days > 1 ? " days ago" : " day ago"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment