-4

I have date array and i set data in my list.

holder.getDayReceipt().setText(receiptList.get(position).getCreatedDate().toString());

I need set date in this format:

Today  (16 June)
1 day  (15 June)
2 day  (14 June)
..............

How do it?

EDIT: You did not understand me

instead "16 June" i want Today
instead "15 June" i want 1 day instead "14 June" i want 2 day

enter image description here

ip696
  • 6,574
  • 12
  • 65
  • 128
  • With bare hands. 1/ compute the offset 2/ some date formatting 3/ output –  Jun 16 '15 at 10:58
  • Search for apis related to java.util.Calendar. Use it according to your requirement. – Prashant Jun 16 '15 at 10:58
  • Possible duplicate of [Simplify replacement of date object with "today" and "yesterday" strings in Java static method](http://stackoverflow.com/questions/4292139/simplify-replacement-of-date-object-with-today-and-yesterday-strings-in-java) – Basil Bourque Oct 30 '16 at 19:25

2 Answers2

0

I suggest to use the Joda library for time

for example:

public boolean isAfterPayDay(DateTime datetime) {
 if (datetime.getMonthOfYear() == 2) {
 // February is month 2!!
 return datetime.getDayOfMonth() > 26;
 }
 return datetime.getDayOfMonth() > 28;
 }
Andrea Cinesi
  • 276
  • 2
  • 10
0

You can implement this piece of code

public String getTimeDiff(long secondsTimeDiff)
{       
    long secondsInOneDay = 84600;
    int maxDaysAgo = 15;

    if ( secondsTimeDiff < secondsInOneDay)
    {
        return "today";
    }
    else if ( secondsTimeDiff < 2*secondsInOneDay)
    {
         return "1 day";
    }
    else if ( secondsTimeDiff < maxDaysAgo*secondsInOneDay)
    {
        int days = (int) (secondsTimeDiff / secondsInOneDay);
        return days + " day";
    }
    else
    {
        //use normal DateUtils logic here...
        return "....";
    }
}

Hope it would be helpful to you!!

Garima Mathur
  • 3,312
  • 3
  • 18
  • 32