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.DateFormat;
  7. import java.text.ParseException;
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. private static final String[] fechas = {
  15. "1/1/16",
  16. "10/1/16",
  17. "1/10/16",
  18. "12/10/16"
  19. };
  20.  
  21. private static final DateFormat parseador = new SimpleDateFormat("d/M/yy");
  22. private static final DateFormat formateador = new SimpleDateFormat("yyyy/MM/dd");
  23.  
  24. public static void main(String[] args) {
  25. for (String fecha : fechas) {
  26. try {
  27. Date d = parseador.parse(fecha);
  28. System.out.println(formateador.format(d));
  29. } catch (ParseException e) {
  30. System.out.println("fecha " + fecha + " no valida");
  31. }
  32. }
  33. }
  34. }
Success #stdin #stdout 0.07s 321344KB
stdin
Standard input is empty
stdout
2016/01/01
2016/01/10
2016/10/01
2016/10/12