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 start = LocalDate.of( 2017 , Month.JANUARY , 23 ) ;
  19. LocalDate stop = LocalDate.of( 2017 , Month.FEBRUARY , 2 ) ;
  20.  
  21. LocalDate ld = start ;
  22. List<LocalDate> dates = new ArrayList<>() ;
  23. while ( ! ld.isAfter( stop ) ) {
  24. dates.add( ld ); // Collect this date.
  25. ld = ld.plusDays( 1 ) ; // Setup the next loop.
  26. }
  27.  
  28. System.out.println( "start: " + start + " | stop: " + stop ) ;
  29. System.out.println( "dates: " + dates ) ;
  30.  
  31.  
  32. }
  33. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
start: 2017-01-23 | stop: 2017-02-02
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]