0
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 写入文本字段。如果我使用如下所示的今天日期,则代码可以正常工作。

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 值传递给我可以操作的日期变量吗?

4

1 回答 1

0

Calendar c = Calendar.getInstance(); c.setTime(new Date()); txtEndDate.setSelectedDate(c);

于 2017-05-11T11:01:12.300 回答