fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.text.SimpleDateFormat;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String dob = "01/08/1990";
  13.  
  14. int month = 0, dd = 0, yer = 0;
  15.  
  16. try {
  17.  
  18. SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
  19. Date d = sdf.parse(dob);
  20. Calendar cal = Calendar.getInstance();
  21. cal.setTime(d);
  22. month = cal.get(Calendar.MONTH);
  23. dd = cal.get(Calendar.DATE);
  24. yer = cal.get(Calendar.YEAR);
  25.  
  26. System.out.println("Month - " + String.format("%02d", (month+1)));
  27. System.out.println("Day - " + String.format("%02d", dd));
  28. System.out.println("Year - " + yer);
  29.  
  30. } catch (Exception e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. }
Success #stdin #stdout 0.05s 712192KB
stdin
Standard input is empty
stdout
Month - 01
Day - 08
Year - 1990