fork(8) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.SimpleDateFormat;
  7. import java.util.Calendar;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
  15. Calendar cal = Calendar.getInstance();
  16. // get starting date
  17. cal.add(Calendar.DAY_OF_YEAR, -6);
  18.  
  19. // loop adding one day in each iteration
  20. for(int i = 0; i< 6; i++){
  21. cal.add(Calendar.DAY_OF_YEAR, 1);
  22. System.out.println(sdf.format(cal.getTime()));
  23. }
  24. }
  25. }
Success #stdin #stdout 0.13s 321280KB
stdin
Standard input is empty
stdout
2016-04-09 
2016-04-10 
2016-04-11 
2016-04-12 
2016-04-13 
2016-04-14