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 = "11-2,2020" ;
  15. DateTimeFormatter fInput = DateTimeFormatter.ofPattern( "M-d,uuuu" ) ;
  16.  
  17. LocalDate ld = LocalDate.parse( input , fInput ) ;
  18.  
  19. DateTimeFormatter fOutput = DateTimeFormatter.ofPattern( "MM-dd-uuuu" ) ;
  20. String output = ld.format( fOutput ) ;
  21.  
  22. System.out.println( input + " ➠ " + output ) ;
  23.  
  24. System.out.println(
  25. LocalDate
  26. .parse( "11-2,2020" , DateTimeFormatter.ofPattern( "M-d,uuuu" ) )
  27. .format( DateTimeFormatter.ofPattern( "MM-dd-uuuu" ) )
  28. );
  29. }
  30. }
Success #stdin #stdout 0.15s 53892KB
stdin
Standard input is empty
stdout
11-2,2020 ➠ 11-02-2020
11-02-2020