java.util.Date Calculate difference in days
I tried to calculate the difference between two dates and I noticed one thing. When calculating only the days, the start of daylight saving time is included in the interval, so the result will be shorter with 1 day. To obtain accurate results, the value of hours also must be considered. For example: SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); Date dfrom = format.parse("03-29-2015"); Date dto = format.parse("03-30-2015"); long diff = dto.getTime() - dfrom.getTime(); System.out.println(diff); System.out.println("Days: "+diff / (24 * 60 * 60 * 1000)); System.out.println("Hours: