fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7.  
  8. import java.time.*;
  9. import java.time.temporal.*;
  10. import java.time.format.*;
  11.  
  12. /* Name of the class has to be "Main" only if the class is public. */
  13. class Ideone
  14. {
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17.  
  18. String startDateString = "2017-03-08";
  19. String finishDateString = "2017-03-10";
  20.  
  21. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH);
  22. LocalDate startDate = LocalDate.parse(startDateString, formatter);
  23. LocalDate finishDate = LocalDate.parse(finishDateString, formatter);
  24.  
  25. Integer day = finishDate.compareTo(startDate);
  26.  
  27. System.out.println( "day: " + day );
  28.  
  29. }
  30. }
Success #stdin #stdout 0.15s 4386816KB
stdin
Standard input is empty
stdout
day: 2