Finally, with JavaFX 8 a DatePicker control was added (for JavaFX 2 we had to create our own)!

The DatePicker works well in combination with the new Java 8 Date and Time API. Those two things together provide a much better experience when working with dates in Java!

JavaFX Date Picker

Basic Usage

Using the DatePicker is straight forward:

// Create the DatePicker.
DatePicker datePicker = new DatePicker();

// Add some action (in Java 8 lambda syntax style).
datePicker.setOnAction(event -> {
    LocalDate date = datePicker.getValue();
    System.out.println("Selected date: " + date);

// Add the DatePicker to the Stage.
StackPane root = new StackPane();
stage.setScene(new Scene(root, 500, 650));;

Using FXML

I usually prefer keeping as much of the view in fxml instead of instantiating the controls in Java code as above. With Scene Builder 2.0 and above you can even drag-and-drop the DatePicker into your fxml.


Hide Week Numbers

We can set the showWeekNumbersProperty to true/false to show/hide a column showing week numbers. Note: The default value depends on the country of the current locale.

JavaFX Date Picker No Weeks


Date Converter

The date in the text field is automatically converted to the local format (in my case, it's dd.MM.yyyy). By setting a StringConverter we can change this, for example, to yyyy-MM-dd.

JavaFX Date Picker Converter

String pattern = "yyyy-MM-dd";


datePicker.setConverter(new StringConverter<LocalDate>() {
     DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(pattern);

     public String toString(LocalDate date) {
         if (date != null) {
             return dateFormatter.format(date);
         } else {
             return "";

     public LocalDate fromString(String string) {
         if (string != null && !string.isEmpty()) {
             return LocalDate.parse(string, dateFormatter);
         } else {
             return null;

Other Calendar Systems

If you need a different chronology, e.g. the Japanese Imperial calendar system, you can change it as follows:

// Japanese calendar.

// Hijrah calendar.

// Minguo calendar.

// Buddhist calendar.

Here is a screenshot of the Hijrah calendar:

Hijrah Calendar