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.LocalDateTime;
  7. import java.time.format.DateTimeFormatter;
  8. import java.text.SimpleDateFormat;
  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.  
  15. SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
  16. String dateInString = "07/06/2013";
  17.  
  18.  
  19. Date date = formatter.parse(dateInString);
  20. System.out.println(date);
  21. formatter.format(date);
  22. System.out.println();
  23.  
  24.  
  25.  
  26. // print both strings
  27. System.out.println("Old Date & Time Format: " + dateInString);
  28. System.out.println("New Date & Time Format: " + date);
  29. }
  30. }
Success #stdin #stdout 0.18s 40172KB
stdin
Standard input is empty
stdout
Fri Jun 07 00:00:00 GMT 2013

Old Date & Time Format: 07/06/2013
New Date & Time Format: Fri Jun 07 00:00:00 GMT 2013