How to sort the dates from current to old date in Android or Java?

android, date, java

Solution

You can go with Comparator and can sort data by using compare()

Collections.sort(dateList, new Comparator<Date>(){
           public int compare(Date date1, Date date2){
          return date1.after(date2);
        }
      });

Problem

I am in a need of function, user defined, which could sort the dates from current time to old time. I'm having list of 10 dates which I want to sort these dates starting from last recent date. Currently I have a logic, in which if we can covert the date in milli-second then comparing it with current-milli-seconds and the least milli-second will be the recent date. That is, ``` CURRENT_MILLI_SECOND - A_DATE_CONVERTED_TO_MILLI_SECONDS = MILLI-SECONDS ``` Please suggest me if anyone can help me in this logic or any other logics...!!! This is the formate which I am getting from server: ``` Thu Dec 27 11:02:43 GMT+05:30 2012 ```

Original source

Related problems