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.  
  19. LocalDate start = LocalDate.of( 2017 , Month.JANUARY , 23 ) ;
  20. LocalDate stop = LocalDate.of( 2017 , Month.FEBRUARY , 3 ) ; // Third instead of the Second of February, to be half-open.
  21.  
  22. LocalDate ld = start ;
  23. List<LocalDate> dates = new ArrayList<>() ;
  24. while ( ld.isBefore( stop ) ) { // Using "isBefore" for Half-Open approach.
  25. dates.add( ld ); // Collect this date.
  26. ld = ld.plusDays( 1 ) ; // Setup the next loop.
  27. }
  28.  
  29. System.out.println( "start: " + start + " | stop: " + stop );
  30. System.out.println( "dates: " + dates );
  31.  
  32.  
  33. }
  34. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
start: 2017-01-23 | stop: 2017-02-03
dates: [2017-01-23, 2017-01-24, 2017-01-25, 2017-01-26, 2017-01-27, 2017-01-28, 2017-01-29, 2017-01-30, 2017-01-31, 2017-02-01, 2017-02-02]