-1

I use the JFXtras library in my project and when i get the value from LocalDateTimeTextField it appeared like this 1 juin 2017 01:00:00

My problem is when I want to set value to it. I tried many methods but do not worked

String date="1 juin 2017 17:00:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d MMM yyyy hh:mm:ss");
LocalDateTime localDate = LocalDateTime.parse(date, formatter);
fieldDate.setDisplayedLocalDateTime(localDate);

I debug my broject and give me the error in this line

 LocalDateTime localDate = LocalDateTime.parse(date, formatter);
Amirouche Zeggagh
  • 3,428
  • 1
  • 25
  • 22
  • 1
    ***....but do not worked...*** how doesnt work? is throwing an exception, is setting another value, is setting nothing at all???? – ΦXocę 웃 Пepeúpa ツ May 08 '17 at 17:22
  • 1
    Never used it (nor JavaFX), but I guess this is the method you want: http://jfxtras.org/doc/8.0/jfxtras-controls/jfxtras/scene/control/LocalDateTimeTextField.html#setLocalDateTime-java.time.LocalDateTime-. Note that your pattern is incorrect. hh should be HH. – JB Nizet May 08 '17 at 17:27
  • it giv me en error in this line LocalDateTime localDate = LocalDateTime.parse(date, formatter); – Amirouche Zeggagh May 08 '17 at 18:15
  • @amirouche and the error is... – JB Nizet May 08 '17 at 18:17

1 Answers1

0

This has nothing to do with JavaFX or JFXtras. Your problem is in parsing a string to LocalDateTime, which is a standard Java 8 class. https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

No matter how the LocalDateTime is formatted per default, you still need to define a pattern that matches. For example the "MMM" requires a three letter month, not a four letter one. https://docs.oracle.com/javase/tutorial/datetime/iso/format.html

Try adding an M and replace the hh with HH: DateTimeFormatter.ofPattern("d MMMM yyyy HH:mm:ss").parse("1 April 2017 17:00:00")

tbeernot
  • 2,473
  • 4
  • 24
  • 31