Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SimpleDateFormat motorola = new SimpleDateFormat("dd 'de' MMM 'de' yyyy"); // compila para MOTOROLA
- SimpleDateFormat samsung = new SimpleDateFormat("dd/MM/yyyy"); //compila para Samsung
- 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)$";
- long unixSeconds = System.currentTimeMillis();
- Date date = new java.util.Date(unixSeconds);
- // o formato que você quer a saida
- SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
- // seta o timezone
- sdf.setTimeZone(java.util.TimeZone.getTimeZone("GMT-4"));
- String formattedDate = sdf.format(date);
- System.out.println(formattedDate);
- String s = "10/04/2019";
- // formatos possíveis
- SimpleDateFormat[] formatos = {
- new SimpleDateFormat("dd 'de' MMM 'de' yyyy"),
- new SimpleDateFormat("dd/MM/yyyy")
- };
- Date data = null; // java.util.Date
- for (SimpleDateFormat sdf : formatos) {
- try {
- data = sdf.parse(s);
- } catch (ParseException e) {
- System.out.println("String está no formato inválido, tentar o próximo");
- }
- }
- if (data != null) {
- System.out.println(data);
- } else {
- System.out.println("Não foi possível obter a data");
- }
- new SimpleDateFormat("dd 'de' MMM 'de' yyyy", new Locale("pt", "BR"))
- SimpleDateFormat formatoSaida = new SimpleDateFormat("dd/MM/yyyy");
- System.out.println(formatoSaida.format(data));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement