先生,我有一个像“08-25-2013”这样的日期作为字符串,我得到了这个字符串日期的天数,现在我添加了几天的数字天,比如漫长的日子=天+ 250;现在的问题是如何将“05-02-2014”这样的日期作为字符串。请尽快回复我,请提前感谢尊敬的先生。 Qustions:转换为日期的天数。
答案 0 :(得分:2)
这样做..
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);
答案 1 :(得分:0)
使用此代码
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);