How to pass the date value of a dateChooserCombo to a variable

4.1k views Asked by At
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()));

I'm trying to selected a Startdate from the dateChooserCombo and increment it by the number of days required to complete a course and then write the endDate to a Textfield. If I use today date as shown below the code works fine.

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()));

Can someone please tell me where am I going wrong or how to pass a dateChooserCombo value to a date variable which I can manipulate?

1

There are 1 answers

1
Nevermind On

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