date - Get the last x day from a string in android (e.g. 20140310 , last 2 day , return 20140308) -


how can serve string date , reduce 2 day, after return result string ?

just similar title example? thanks

this related code seems deduct current date , not output string e.g. 20140308, thanks

calendar calendar = calendar.getinstance();  calendar.add(calendar.date, -2); 

you can use simpledateformat parse string date based on pattern of choice - in case yyyymmdd.

then can perform operations on date want re-format string based on pattern.

simpledateformat sdf = new simpledateformat("yyyymmdd"); //set simpledateformat per pattern     string datestr = "20140310"; // date string     calendar cal = calendar.getinstance();     cal.settime(sdf.parse(datestr)); // set date calendar instance     cal.add(calendar.date, -2); // perform operation      system.out.println(sdf.format(cal.gettime())); //20140308 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -