janeide
Novembro 10, 2016, 12:46pm
#1
Pessoal, alguém pode me ajudar, estou tentenado converter de String para DateTimeFormatter no formato yyyy-MM-dd HH:mm, porem, ele me retorna algo estrano como 1986-04-08T12:30 e a data não esta no formato correto alguém pode me ajudar?
String str = "1986-04-08 12:30";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime dateTime = LocalDateTime.parse(str, formatter);
System.out.println(dateTime);
1986-04-08T12:30
vc esta imprimindo a data baseada na ISO_8601 ué, baseada na documentação isso é o que acontece (vc leu a documentação não leu? )
ISO 8601 Data elements and interchange formats – Information interchange – Representation of dates and times is an international standard covering the exchange of date- and time-related data. It was issued by the International Organization for Standardization (ISO) and was first published in 1988. The purpose of this standard is to provide an unambiguous and well-defined method of representing dates and times, so as to avoid misinterpretation of numeric representations of dates and times, particu...
veja o javadoc:
https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#toString--
logo não é estranho : vc apenas não especificou qual o formato que vc quer escrever o seu objeto ( vc informou para ler )
se vc usar o metodo format e passar o formato que vc quer, ai começamos a nos entender.
https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#format-java.time.format.DateTimeFormatter-