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

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?

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
Herb21
  • 365
  • 1
  • 6
  • 12
  • What is the return type of dateChooserCombo1.getSelectedDate()? Not a Date? – Manu Jun 18 '15 at 14:13
  • Maybe [this](http://stackoverflow.com/questions/21012751/get-jdatechooser-date-to-jlabel) could help, or [this one](http://stackoverflow.com/questions/23564363/getting-value-from-jdatechooser-and-saving-to-ms-sql-db) or [this one](http://stackoverflow.com/questions/6760690/can-not-retrieve-date-from-jdatechooser-in-java). – Frakcool Jun 18 '15 at 14:26
  • @Frakcool the .getDate is not available with a dateChooserCombo.. any more suggestions – Herb21 Jun 19 '15 at 05:55
  • If getSelectedDate() returns a Date and you want a Date, why would you call toString() and parse it to a Date again? – Manu Jun 19 '15 at 09:31

1 Answers1

0

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