fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5.  
  6. import java.util.Date;
  7. import java.util.Calendar;
  8. import java.util.GregorianCalendar;
  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. String date = "06/25/20014";
  16. try {
  17. String validDate = "MM/dd/yyyy";
  18. SimpleDateFormat format = new SimpleDateFormat(validDate);
  19. format.setLenient(false);
  20. Date theDate = format.parse(date);
  21. c.setTime(theDate);
  22. int year = c.get(Calendar.YEAR);
  23. int month = c.get(Calendar.MONTH);
  24. int day = c.get(Calendar.DAY_OF_MONTH);
  25. int pos = c.get(Calendar.DAY_OF_WEEK);
  26. if (Calendar.WEDNESDAY == pos)
  27. System.out.print("day is Wednesday on " + year + "/" + (month+1) + "/" + day);
  28. }
  29. catch (ParseException e) {
  30. System.out.print("Cought exception " + e );
  31. }
  32. }
  33. }
Success #stdin #stdout 0.14s 321088KB
stdin
Standard input is empty
stdout
day is Wednesday on 20014/6/25