fork(2) 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.temporal.*;
  9. import java.time.format.*;
  10.  
  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.  
  19. ZoneId z = ZoneId.of( "America/Montreal" );
  20. LocalDate today = LocalDate.now( z );
  21.  
  22. LocalDate earlier = today.minusMonths( 2 ).minusWeeks( 3 ).minusDays( 2 ) ;
  23.  
  24. Period p = Period.between( earlier , today ) ;
  25. int years = p.getYears();
  26. int months = p.getMonths();
  27. int days = p.getDays();
  28.  
  29. String output = p.toString() ;
  30.  
  31. System.out.println( "earlier.toString(): " + earlier );
  32. System.out.println( "today.toString(): " + today );
  33. System.out.println( "p.toString(): " + p );
  34.  
  35.  
  36.  
  37. }
  38. }
Success #stdin #stdout 0.15s 4386816KB
stdin
Standard input is empty
stdout
earlier.toString(): 2017-02-10
today.toString(): 2017-05-05
p.toString(): P2M25D