How to sort RSS by date

So, if you’ve got one or more RSS feeds and you want to sort them according to the pubdate, do this:

Collections.sort(myFeedsList, new Comparator<RssItemModel>() {

            @Override
            public int compare(RssItemModel lhs, RssItemModel rhs) {
                SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
                try {
                    Date date1 = formatter.parse(rhs.getPubDate());
                    Date date2 = formatter.parse(lhs.getPubDate());
                    return date1.compareTo(date2);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                return 0;
            }
        });
FacebookGoogle BookmarksTwitterFriendFeedGoogle GmailBlogger PostGoogle ReaderHotmailWordPressShare

Related posts:

  1. Java: Playing with Date, Time, Calendar and SimpleDateFormat
  2. Android sorting an ArrayList
  3. Create MD5 hashes in Android
  4. Ignore fields at Elastic Search
  5. Check if device has Android Market

Tags: , ,

Leave a Comment