如何将dateChooserCombo的日期值传递给变量

时间:2015-06-18 13:52:02

标签: java swing jdatechooser

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

1 个答案:

答案 0 :(得分:0)

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