fork(4) 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 data = "2013-01-08T20:11:48Z";
  15. DateTimeFormatter originalFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
  16. DateTimeFormatter targetFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
  17.  
  18. // Com isso já da pra fazer várias manipu
  19. LocalDateTime dateTime = LocalDateTime.parse(data, originalFormat);
  20.  
  21. // ou assim
  22. DateTimeFormatter formatador = DateTimeFormatter
  23. .ofLocalizedDateTime(FormatStyle.MEDIUM)
  24. .withLocale(new Locale("pt", "br"));
  25.  
  26. // ou assim
  27. ZonedDateTime zoned = dateTime.atZone(ZoneId.of("America/Sao_Paulo"));
  28. DateTimeFormatter formatador2 = DateTimeFormatter
  29. .ofLocalizedDateTime(FormatStyle.LONG)
  30. .withLocale(new Locale("pt", "br"));
  31.  
  32. System.out.println(data);
  33. System.out.println(dateTime.format(targetFormat));
  34. System.out.println(zoned.format(formatador));
  35. System.out.println(zoned.format(formatador2));
  36. }
  37. }
Success #stdin #stdout 0.17s 4386816KB
stdin
Standard input is empty
stdout
2013-01-08T20:11:48Z
08/01/2013 20:11:48
Jan 8, 2013 8:11:48 PM
January 8, 2013 8:11:48 PM BRST