+ 3

Difference of two dates between Jtextfield and Jdatechooser

How do i get the difference between jtextfield and jdatechooser in order to compute the duration(number of days) but there's no error or warning sign that being indicated in my codes? can you help me on how to initialize and the process correctly? Thanks in advance peeps :) ------Codes------ JTextField dateborrowed = new JTextField(); JDateChooser DateReturnedChooser = new JDateChooserChooser(); try{ Db = dformat.parse(dformat.format(dateborrowed.getText())); Dr = dformat.parse(dformat.format(DateReturnedChooser.getDate())); long diff = Dr.getTime()-Db.getTime(); long hours = diff/(60*60*1000); long days = hours/24; if(days<0){ days*=-1; Math.abs(days); Duration.setText(Long.toString(days)); } else{ Math.abs(days); Duration.setText(Long.toString(days)); } } catch(Exception ec){ JOptionPane.showMessageDialog(null,"Invalid date","Library System",0); }

11th May 2019, 12:25 PM
Daryll Culas
Daryll Culas - avatar
1 ответ
21st May 2019, 10:53 AM
Gordon
Gordon - avatar