fork 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.*;
  7. import java.time.*;
  8. import java.time.format.*;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11.  
  12. class Main {
  13.  
  14. public static void main(String[] args) {
  15. String dateString = "03/26/2012 11:49:00 AM";
  16. SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa", Locale.GERMAN);
  17. Date convertedDate = new Date();
  18. try {
  19. convertedDate = dateFormat.parse(dateString);
  20. } catch (ParseException e) {
  21. // TODO Auto-generated catch block
  22. e.printStackTrace();
  23. }
  24. System.out.println(convertedDate);
  25. }
  26. }
Success #stdin #stdout #stderr 0.25s 59188KB
stdin
Standard input is empty
stdout
Sun Aug 10 16:57:54 GMT 2025
stderr
java.text.ParseException: Unparseable date: "03/26/2012 11:49:00 AM"
	at java.base/java.text.DateFormat.parse(DateFormat.java:395)
	at Main.main(Main.java:19)