Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. SimpleDateFormat motorola = new SimpleDateFormat("dd 'de' MMM 'de' yyyy"); // compila para MOTOROLA
  2. SimpleDateFormat samsung = new SimpleDateFormat("dd/MM/yyyy"); //compila para Samsung
  3.  
  4. String DatePattern = "^(?:(31)(D)(0?[13578]|1[02])2|(29|30)(D)(0?[13-9]|1[0-2])5|(0?[1-9]|1d|2[0-8])(D)(0?[1-9]|1[0-2])8)((?:1[6-9]|[2-9]d)?d{2})$|^(29)(D)(0?2)12((?:1[6-9]|[2-9]d)?(?:0[48]|[2468][048]|[13579][26])|(?:16|[2468][048]|[3579][26])00)$";
  5.  
  6. long unixSeconds = System.currentTimeMillis();
  7. Date date = new java.util.Date(unixSeconds);
  8. // o formato que você quer a saida
  9. SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
  10. // seta o timezone
  11. sdf.setTimeZone(java.util.TimeZone.getTimeZone("GMT-4"));
  12. String formattedDate = sdf.format(date);
  13. System.out.println(formattedDate);
  14.  
  15. String s = "10/04/2019";
  16. // formatos possíveis
  17. SimpleDateFormat[] formatos = {
  18. new SimpleDateFormat("dd 'de' MMM 'de' yyyy"),
  19. new SimpleDateFormat("dd/MM/yyyy")
  20. };
  21. Date data = null; // java.util.Date
  22. for (SimpleDateFormat sdf : formatos) {
  23. try {
  24. data = sdf.parse(s);
  25. } catch (ParseException e) {
  26. System.out.println("String está no formato inválido, tentar o próximo");
  27. }
  28. }
  29. if (data != null) {
  30. System.out.println(data);
  31. } else {
  32. System.out.println("Não foi possível obter a data");
  33. }
  34.  
  35. new SimpleDateFormat("dd 'de' MMM 'de' yyyy", new Locale("pt", "BR"))
  36.  
  37. SimpleDateFormat formatoSaida = new SimpleDateFormat("dd/MM/yyyy");
  38. System.out.println(formatoSaida.format(data));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement