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.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. LocalDate anchor = LocalDate.of( 2015 , Month.FEBRUARY , 2 );
  19.  
  20. LocalDate feb5 = LocalDate.of( 2015 , Month.FEBRUARY , 5 );
  21. LocalDate feb8 = LocalDate.of( 2015 , Month.FEBRUARY , 8 );
  22. LocalDate feb9 = LocalDate.of( 2015 , Month.FEBRUARY , 9 );
  23.  
  24. System.out.println( feb5 + " is in week # " + ( ChronoUnit.WEEKS.between( anchor , feb5 ) + 1 ) );
  25. System.out.println( feb8 + " is in week # " + ( ChronoUnit.WEEKS.between( anchor , feb8 ) + 1 ) );
  26. System.out.println( feb9 + " is in week # " + ( ChronoUnit.WEEKS.between( anchor , feb9 ) + 1 ) );
  27.  
  28.  
  29. }
  30. }
Success #stdin #stdout 0.2s 33972KB
stdin
Standard input is empty
stdout
2015-02-05 is in week # 1
2015-02-08 is in week # 1
2015-02-09 is in week # 2