13 28 Date formating
In our JavaFX to-do list, each task carries a deadline stored as a java.time.LocalDate. When we display it through LocalDate.toString(), the output uses the ISO format such as 2022-05-12. This is correct but not very readable for end users, who would rather see something like May 12, 2022 or 12/05/2022. This is exactly the job of DateTimeFormatter, the modern Java class for formatting dates and times.
Using DateTimeFormatter
We declare a formatter, usually as a constant or a field on the controller, choosing a pattern that fits the audience:
private static final DateTimeFormatter DATE_FMT =
DateTimeFormatter.ofPattern("MMM d, yyyy");
The pattern uses standard letters: yyyy for the year, MM for the month as a number, MMM for the short month name, MMMM for the full month name, and d or dd for the day.
To display a deadline, we ask the formatter to convert the LocalDate to a String, then push it into the label that lives on the right side of the BorderPane:
deadlineLabel.setText(item.getDeadline().format(DATE_FMT));
If we want the format to match the user's locale, we can use predefined styles such as DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM) with Locale.FRANCE or Locale.US. The same pattern logic also works for LocalDateTime when both the date and the time of day are needed.
With a formatter in place, every time the selection changes in the ListView, the deadline is shown in a clean, human-friendly way, while the underlying LocalDate stays untouched and easy to compare or sort.