SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy",Locale.ENGLISH);
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.setTime(sdf.parse(dateChooserCombo1.getSelectedDate().toString()));//code to select date from the dateChooserCombo and Parse as string
int x = Integer.parseInt(txtDays.getText());
c.add(Calendar.DATE, x);
SimpleDateFormat print = new SimpleDateFormat("yyyy/MM/dd");
txtEndDate.setText(print.format(c.getTime()));
我试图从dateChooserCombo中选择一个Startdate,并将其增加完成课程所需的天数,然后将endDate写入Textfield。如果我今天使用如下所示的日期,则代码可以正常工作。
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy",Locale.ENGLISH);
Calendar c = Calendar.getInstance();
c.setTime(new Date());
//c.setTime(sdf.parse(dateChooserCombo1.getSelectedDate().toString()));
int x = Integer.parseInt(txtDays.getText());
c.add(Calendar.DATE, x);
//SimpleDateFormat print = new SimpleDateFormat("yyyy/MM/dd");
txtEndDate.setText(sdf.format(c.getTime()));
有人可以告诉我哪里出错了,或者如何将dateChooserCombo值传递给我可以操作的日期变量?
答案 0 :(得分:0)
Calendar c = Calendar.getInstance();
c.setTime(new Date());
txtEndDate.setSelectedDate(c);