fork(6) 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.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. System.out.println( // At least 12 years, depending on current year.
  16. ChronoUnit.YEARS.between(
  17. LocalDate.of ( 2010 , 1 , 1 ) ,
  18. LocalDate.now ( ZoneId.of( "America/Montreal" ) )
  19. )
  20. );
  21. System.out.println( // Zero years
  22. ChronoUnit.YEARS.between(
  23. LocalDate.of( 2010 , 1 , 1 ) ,
  24. LocalDate.of( 2010 , 6 , 1 )
  25. )
  26. );
  27. System.out.println( // One year.
  28. ChronoUnit.YEARS.between(
  29. LocalDate.of( 2010 , 1 , 1 ) ,
  30. LocalDate.of( 2011 , 1 , 1 )
  31. )
  32. );
  33. System.out.println( // One year.
  34. ChronoUnit.YEARS.between(
  35. LocalDate.of( 2020 , 11 , 23 ) ,
  36. LocalDate.of( 2022 , 9 , 12 )
  37. )
  38. );
  39. }
  40. }
Success #stdin #stdout 0.14s 55828KB
stdin
Standard input is empty
stdout
12
0
1
1