fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.*;
  8. import java.time.temporal.*;
  9. import java.time.format.*;
  10.  
  11.  
  12. /* Name of the class has to be "Main" only if the class is public. */
  13. class Ideone
  14. {
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17.  
  18. DateTimeFormatter f = DateTimeFormatter.ofPattern( "MMdduuuu" );
  19. String input = String.format("%08d", 3222017) ;
  20. LocalDate localDate = LocalDate.parse( input , f );
  21. String output = localDate.toString();
  22. LocalDate localDate2 = LocalDate.parse( output ); // ISO 8601 strings parsed by default without specifing a formatting pattern.
  23.  
  24. System.out.println( "input: " + input );
  25. System.out.println( "output: " + output );
  26. System.out.println( "localDate2.toString(): " + localDate2 );
  27.  
  28. }
  29. }
Success #stdin #stdout 0.14s 4386816KB
stdin
Standard input is empty
stdout
input: 03222017
output: 2017-03-22
localDate2.toString(): 2017-03-22