fork(1) 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.DateFormat;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Date;
  9. import java.util.Calendar;
  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. Date x = parse("Oct 1, 1997, 12:00:00 AM", "MMM d, yyyy, hh:mm:ss a");
  17. System.out.println("X String: " + x);
  18. }
  19.  
  20. public static Date parse(String dateString, String dateFormat) {
  21. SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
  22. sdf.setLenient(false);
  23. try {
  24. return sdf.parse(dateString);
  25. } catch (Exception e) {
  26. System.out.println("E???");
  27. return null;
  28. }
  29. }
  30. }
Success #stdin #stdout 0.2s 40256KB
stdin
Standard input is empty
stdout
X String: Wed Oct 01 00:00:00 GMT 1997