-3

I having students list of admission and in that I have to show student with color when that student get admitted with current date and time suppose todays date and time like this 08/08/2018 12:36pm getting through the json. So I have to show that student with color till tomorrow means 09/08/2018 12:36pm,how can I keep that student record with color till 24 Hours and after completing of 24 Hours want to remove color and keep it normal. Thanks in Advance.
Now I compared only dates

 if (SystemDte.equals(DataBaseDate)) {

        try {
            viw.setBackgroundColor(Color.parseColor("#ffff00"));

        } catch (Exception e) {

            e.printStackTrace();
        }
    }
    else {
        try {
            viw.setBackgroundColor(Color.parseColor("#CABBBBBB"));
        } catch (Exception e) {

            e.printStackTrace();
        }
    }
Ionic
  • 59
  • 5
  • 2
    https://stackoverflow.com/questions/15360123/time-difference-between-two-times – ADM Aug 08 '18 at 07:17

1 Answers1

2

I did it compare two dates and check that diffDays exactly equal to zero and DiffHours,DiffMinute less than equal to zero


SimpleDateFormat format = new

SimpleDateFormat("dd/MM/yyyy HH:mm");

    Date d1 = null;

    Date d2 = null;

    try {
        d1 = format.parse(sysmDte);

        d2 = format.parse(serverDte);

        //in milliseconds
        diff = d2.getTime() - d1.getTime();


        diffMinutes = diff / (60 * 1000) % 60;

        diffHours = diff / (60 * 60 * 1000) % 24;

        diffDays = diff / (24 * 60 * 60 * 1000);

        System.out.print(diffDays + " days, ");

        System.out.print(diffHours + " hours, ");

        System.out.print(diffMinutes + " minutes,");


    } catch (Exception e) {
        e.printStackTrace();
    }
   // for version 1.6
    if (diffDays == 0 && diffHours <= 0 && diffMinutes <= 0) {
        try {
            viw.setBackgroundColor(Color.parseColor("#ffff00"));

        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        try {
            viw.setBackgroundColor(Color.parseColor("#CABBBBBB"));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Ionic
  • 59
  • 5