java - parse a date from string gives exception in android -
i want parse string string date ,date of format tuesday march 19,2015
. want parse , format yyyy-dd-mm
format. below code gives me exception "unparceble date".
code :
dateformat df1 = new simpledateformat("yyyy-mm-dd"); try { date1 = df1.parse(currentdate); system.out .println("============my formated date====================" + date1.tostring()); calendar cal = calendar.getinstance(); cal.settime(date1); cal.add(calendar.date, 10); // add 10 days date1 = cal.gettime(); system.out.println("==============added date==============" + date1.tostring());
i have created 1 common function convert date format. have pass old date format, new date format , date.
public static string convertdateformat(string oldformat, string newformat, string inputdate) { dateformat thedateformat = new simpledateformat(oldformat); date date = null; try { date = thedateformat.parse(inputdate); } catch (parseexception parseexception) { // date invalid. want. } catch (exception exception) { // generic catch. want. } thedateformat = new simpledateformat(newformat); return thedateformat.format(date).tostring(); }
// call funcation
string converteddate = convertdateformat("eeee mmm dd,yyyy","yyyy-mm-dd",datetoconvert);
Comments
Post a Comment