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.text.SimpleDateFormat;
  8. import java.util.Calendar;
  9. import java.util.GregorianCalendar;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16. SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
  17.  
  18. Calendar cp1 = GregorianCalendar.getInstance();
  19. cp1.set(Calendar.DAY_OF_MONTH, 1); //THIS LINE WORKS NOW
  20. System.out.println(cp1.getTime()); // or any method that will use private computeTime()
  21. cp1.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
  22. System.out.println(sdf.format(cp1.getTime()));
  23.  
  24. cp1 = GregorianCalendar.getInstance();
  25. cp1.set(Calendar.DAY_OF_MONTH, 1); //THIS LINE WORKS NOW
  26. cp1.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
  27. System.out.println(sdf.format(cp1.getTime()));
  28. }
  29. }
Success #stdin #stdout 0.09s 2184192KB
stdin
Standard input is empty
stdout
Tue Jan 01 17:18:16 GMT 2019
31/12/2018
28/01/2019