fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.Scanner;
  7. import java.util.Calendar;
  8. import java.util.Locale;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. SimpleDateFormat in = new SimpleDateFormat("dd/MM/yyyy");
  16. try {
  17. Date data = in.parse("05/08/2015");
  18. Calendar cal = Calendar.getInstance();
  19. cal.setTime(data);
  20. int year = cal.get(Calendar.YEAR);
  21. int month = cal.get(Calendar.MONTH);
  22. int day = cal.get(Calendar.DAY_OF_MONTH);
  23.  
  24. System.out.println(year);
  25. System.out.println(month);
  26. System.out.println(day);
  27.  
  28. System.out.println(Locale.getDefault());
  29. } catch (ParseException e) {
  30. e.printStackTrace();
  31. }
  32. }
  33. }
Success #stdin #stdout 0.14s 321280KB
stdin
Standard input is empty
stdout
2015
7
5
en_US