Sir I have a date like "08-25-2013" as a string, I got the number of days from this string date, now I add few number days in it like long days=days+250; now the question is how can I get the date like "05-02-2014" as a string. Please answer me as soon as possible please thanks in advance respected sir. Qustions: number of days convert to the date.
Do this Way..
Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
// display the current date
String CurrentDate = mYear + "/" + mMonth + "/" + mDay;
String dateInString = CurrentDate; // Start date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
c = Calendar.getInstance();
try {
c.setTime(sdf.parse(dateInString));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
c.add(Calendar.DATE, 7656);//insert the number of days you want to be added to the current date
sdf = new SimpleDateFormat("dd/MM/yyyy");
Date resultdate = new Date(c.getTimeInMillis());
dateInString = sdf.format(resultdate);
//Display the Result in the Edit Text or Text View your Choice
EditText etDOR = (EditText)findViewById(R.id.etDateOfReturn);
etDOR.setText(dateInString);
Use this code
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date dateparsed = sdf.parse("29-08-2013");
Calendar c = Calendar.getInstance();
c.setTime(dateparsed);
c.add(Calendar.DATE, 250); // Adding n number of days
String output = sdf.format(c.getTime());
System.out.println(output);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.