I am developing an application for sending SMS. I am storing the current time and showing in the sent history page by retrieving the time from the database. In the sent history page I want to display the time of the message was sent. Here I want to check that the message has been sent today or yesterday or the the day before yesterday like that. If the message was sent yesterday means then I need to display "Yesterday 20:00" like that and even the message was sent yesterday before means "Monday 20:00". I don't know how it has to be done. Please help me if anybody knows.
text. DateFormat. getDateTimeInstance(). format(new Date()); // textView is the TextView view that should display it textView.
get(Calendar. DAY_OF_MONTH) + 1; will it display tomorrow's date. or just add one to today's date? For example, if today is January 31.
To check if date is today, use Android utils library
DateUtils.isToday(long timeInMilliseconds)
This utils class also offers human readable strings for relative times. For example,
DateUtils.getRelativeTimeSpanString(long timeInMilliseconds) -> "42 minutes ago"
The are several parameters you can play with to define how precise the time span should be
See DateUtils
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With