java - Filter list according to Current date android -


i have arraylist<customobject> contains entries. each entry has date associated it. currently, date stored string. eg "2014-09-23t12:45:00"

i want filter list refined list containing entries done today.

iam using pattern achieve this. iam receiving null list after filtering.

here code:--

public class articlefilter implements predicate<statusresponse> {     private final pattern pattern;      public articlefilter(final string regex)     {         pattern = pattern.compile(regex);     }      @override     public boolean apply(final statusresponse input)     {         string datestring =  input.getstarttime();          datestring =  datestring.split("t")[0]; // getting date         return pattern.matcher(datestring).find();     } } 

main.java

calendar currentdate = calendar.getinstance(); //get current date             simpledateformat formatter= new simpledateformat("yyyy/mm/dd"); //format per requirement             string datenow = formatter.format(currentdate.gettime());             arraylist<statusresponse> filteredresultlist = lists.newarraylist(collections2.filter(resultlist, new articlefilter(datenow))); 

the problem here lies in formatter.

you have specified simpledateformat of "yyyy/mm/dd", tell date stored string in format "2014-09-23t12:45:00". need change simpledateformat match format of date string in statusresponse class.

change

simpledateformat formatter= new simpledateformat("yyyy-mm-dd"); 

that fixes imediate problem. however, recommend don't deal string representations of dates @ all, , instead change code deal directly calendar only?

for instance, have statusresponse.getstarttime method return calendar representing start time, have articlefilter constructor take calendar representing day filter on, , have apply method check both calendars return same value get(calendar.year) , get(calendar.day_of_year)


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -