fork(70) 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.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String dt = "1970-12-31"; // Start date
  14. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  15. Calendar c = Calendar.getInstance();
  16. c.setTime(sdf.parse(dt));
  17. c.add(Calendar.DATE, 1); // number of days to add
  18. dt = sdf.format(c.getTime()); // dt is now the new date
  19. System.out.println(dt);
  20. }
  21. }
Success #stdin #stdout 0.13s 321088KB
stdin
Standard input is empty
stdout
1971-01-01