I have a function:
public String getTimePast(Date d) { //insertcodehere } That takes in a Date of a message and must return how much time has past based on the current time in specific format. For example if it has just been posted it will say "Now"
If it has been 4 minutes it will say "4min" If it has been 23hrs it will say "23hrs" Etc
Below is how I tried to do it with no luck! How am I able to do this? Thank you!
public String getTimePast(Date d) { Calendar c = Calendar.getInstance(); int hr = c.get(Calendar.HOUR_OF_DAY); int min = c.get(Calendar.MINUTE); int day = c.get(Calendar.DAY_OF_MONTH); int month = c.get(Calendar.MONTH); int year = c.get(Calendar.YEAR); if (year == d.getYear()) { if (month == d.getMonth()) { if (day == d.getDay()) { if (hr == d.getHours()) { if (min == d.getMinutes()) { return "Now"; } else { return min - d.getMinutes() + "m"; } } else { return hr - d.getHours() + "hr"; } } else { return day - d.getDay() + "d"; } } else { return month - d.getMonth() + "m"; } } else { return year - d.getYear() + "y"; } }