私は文字列として「08-25-2013」のような日付を持っています。この文字列の日付から日数を取得しました。今度は長い日 = 日 + 250 のように数日を追加します。問題は、「2014 年 5 月 2 日」のような日付を文字列として取得する方法です。できるだけ早く回答してください。よろしくお願いします。質問: 日数を日付に変換します。
1298 次
2 に答える
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);
于 2013-10-08T08:44:06.047 に答える
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);
于 2013-10-08T08:48:02.190 に答える