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. import java.time.*;
  8. import java.time.format.*;
  9. import java.time.temporal.*;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16.  
  17. LocalDate start = LocalDate.of( 2016, Month.MARCH, 28 ) ; // inclusive
  18. LocalDate stop = LocalDate.of( 2016, Month.APRIL, 1 ) ; // exclusive
  19.  
  20. Period p = Period.between( start , stop );
  21.  
  22. long daysBetween = ChronoUnit.DAYS.between( start, stop );
  23.  
  24. System.out.println( "start/stop: " + start + "/" + stop );
  25. System.out.println( "p.toString(): " + p );
  26. System.out.println( "daysBetween: " + daysBetween );
  27.  
  28.  
  29. }
  30. }
Success #stdin #stdout 0.09s 711680KB
stdin
Standard input is empty
stdout
start/stop: 2016-03-28/2016-04-01
p.toString(): P4D
daysBetween: 4