1LocalDate start = LocalDate.parse("2020-11-03");
2LocalDate end = LocalDate.parse("2020-12-15");
3
4long diff = DAYS.between(start, end);
1import java.util.Date;
2import java.text.SimpleDateFormat;
3class Example{
4 public static void main(String args[]){
5 SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
6 String dateBeforeString = "31 01 2014";
7 String dateAfterString = "02 02 2014";
8
9 try {
10 Date dateBefore = myFormat.parse(dateBeforeString);
11 Date dateAfter = myFormat.parse(dateAfterString);
12 long difference = dateAfter.getTime() - dateBefore.getTime();
13 float daysBetween = (difference / (1000*60*60*24));
14 /* You can also convert the milliseconds to days using this method
15 * float daysBetween =
16 * TimeUnit.DAYS.convert(difference, TimeUnit.MILLISECONDS)
17 */
18 System.out.println("Number of Days between dates: "+daysBetween);
19 } catch (Exception e) {
20 e.printStackTrace();
21 }
22 }
23}