getting the difference between date in days in java -


Possible duplicates:

I am trying something like this, where I am trying to get the date from Cambobox

  Calendar start = calendar.Ast Instance (); Calendar End = Calendar. Just Instance (); Int Sdate = Integer.print (cmbSdate.getSelectedItem). ToString ()); Int'mmonth = CMBMMath.GetSelected Index (); Int sair = integer. ParisInt (CMBCIrGetSchlightTime) .Toastring ()); IntetAdit = Integr .Presscent (cmbEdate.getSelectedItem (.) ToString ()); Favored Emonth = cmbEmonth.getSelectedIndex (); Int eye = integer. ParisInt (CMBEARGETSchlightIT) (.) Toasting ()); Start.set (Syear, Smonth, Sdate); End.set (Eyear, Emonth, EDATE); Date format date format = new simpledate format ("yY-MM-DD"); String Startdate = Datformat. Format (start.getTime ()); String end date = dateform.form (end.getTime ());  

I can not subtract the end and the due date how do I get the difference between start date and end date?

calendar start = calendar.Ast Instance (); Calendar End = Calendar. Just Instance (); Start.set (2010, 7, 23); Endset (2010, 8, 26); Start start date = start.getTime (); Date end date = end Gate time (); Long startTime = startDate.getTime (); Long end time = end date .get time (); Long diffTime = endtime - initial time; Long diffDays = diffTime / (1000 × 60 * 60 * 24); Date format date format = date format.getateinstance (); Difference between system.out.println ("+ dateFormat.format + +" and "+ dateFormat.format + +" + "diffDays +" "day");

This will not work while crossing the daylight savings time (or leap seconds) as Orange 80 and it can not produce expected results while using different time of day . Using JodaTime can be easy for the right results, because I know that the only correct way with plain Java is to use Calendar and to calculate the method before or after: add .add (


Comments