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.time.* ;
  7. import java.time.format.* ;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. String input = "Apr 1 2022 12:00:00:000AM".replace( " " , " " ) ;
  15. Locale locale =new Locale( "en" , "US" ) ;
  16. DateTimeFormatter formatter =
  17. DateTimeFormatter
  18. .ofPattern("MMM d yyyy hh:mm:ss:SSSa")
  19. .withLocale( locale );
  20. LocalDateTime ldt = LocalDateTime.parse( input , formatter ) ;
  21. LocalDate ld = ldt.toLocalDate();
  22. String output = ld.format( DateTimeFormatter.BASIC_ISO_DATE ) ;
  23. System.out.println( output ) ;
  24. }
  25. }
Success #stdin #stdout 0.18s 59988KB
stdin
Standard input is empty
stdout
20220401