android - Unparseable date. Parse Exception comparing two dates -
i trying produce list based on date. keep getting parse exception. thought had dates in exact same format. maybe missed something. have played hours no success. appreciated.
public static list<string> getmonthlydates(date startdate, date enddate) { list<string> dates = new arraylist<string>(); calendar calendar = new gregoriancalendar(); calendar.settime(startdate); while (calendar.gettime().before(enddate)) { simpledateformat df = new simpledateformat("yyyy-mm-dd"); string result = df.format(calendar.gettime()); dates.add(result); calendar.add(calendar.month, 1); } return dates; } calendar mcalendar = calendar.getinstance(); string dd = editbillduedate.gettext().tostring(); //which shows correctly in format of 2015-jun-15 simpledateformat format = new simpledateformat("yyyy-mm-dd"); //it makes no difference if format yyyy-mm-dd date date; try { //this line below getting error date = format.parse(dd); mcalendar.add(calendar.day_of_year, 365); final date newdate2 = mcalendar.gettime(); list<string> datelist = getmonthlydates(date, newdate2); (final string d1 : datelist) { //does irrelevant } } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); }
if want parse dates in same format 2015-jun-15, should change simpledateformat have 3 characters month element this: yyyy-mmm-dd. change :
simpledateformat format = new simpledateformat("yyyy-mm-dd"); to:
simpledateformat format = new simpledateformat("yyyy-mmm-dd"); and this:
simpledateformat df = new simpledateformat("yyyy-mm-dd"); to:
simpledateformat df = new simpledateformat("yyyy-mmm-dd");
Comments
Post a Comment