Class LocalDateStringConverter

java.lang.Object
javafx.util.StringConverter<LocalDate>
javafx.util.converter.LocalDateStringConverter

public class LocalDateStringConverter extends StringConverter<LocalDate>
A StringConverter implementation for LocalDate values.
Since:
JavaFX 8u40
See Also:
  • Constructor Details

    • LocalDateStringConverter

      public LocalDateStringConverter()

      Creates a LocalDateStringConverter that uses a formatter and parser based on IsoChronology, FormatStyle.SHORT, and the user's Locale.

      This converter ensures symmetry between the toString() and fromString() methods. Many of the default locale based patterns used by DateTimeFormatter will display only two digits for the year when formatting to a string. This would cause a value like 1955 to be displayed as 55, which in turn would be parsed back as 2055. This converter modifies two-digit year patterns to always use four digits. The input parsing is not affected, so two digit year values can still be parsed leniently as expected in these locales.

    • LocalDateStringConverter

      public LocalDateStringConverter(FormatStyle dateStyle)
      Creates a LocalDateStringConverter that uses a formatter and parser based on IsoChronology, the specified FormatStyle, and the user's Locale.
      Parameters:
      dateStyle - the FormatStyle that will be used by the formatter and parser. If null, FormatStyle.SHORT will be used.
    • LocalDateStringConverter

      public LocalDateStringConverter(FormatStyle dateStyle, Locale locale, Chronology chronology)
      Creates a LocalDateStringConverter that uses a formatter and parser based on the given FormatStyle, Locale, and Chronology.
      Parameters:
      dateStyle - the FormatStyle that will be used by the formatter and parser. If null, FormatStyle.SHORT will be used.
      locale - the Locale that will be used by the formatter and parser. If null, the user's locale will be used.
      chronology - the Chronology that will be used by the formatter and parser. If null, IsoChronology.INSTANCE will be used.
    • LocalDateStringConverter

      public LocalDateStringConverter(DateTimeFormatter formatter, DateTimeFormatter parser)

      Creates a LocalDateStringConverter that uses the given formatter and parser.

      For example, to use a fixed pattern for converting both ways:

      String pattern = "yyyy-MM-dd";
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
      StringConverter<LocalDate> converter = DateTimeStringConverter.getLocalDateStringConverter(formatter, null);
      

      Note that the formatter and parser can be created to handle non-default Locale and Chronology as needed.

      Parameters:
      formatter - the formatter that will be used by the toString() method. If null, a default formatter will be used.
      parser - the parser that will be used by the fromString() method. This can be identical to formatter. If null, formatter will be used, and if that is also null, a default parser will be used.
  • Method Details

    • fromString

      public LocalDate fromString(String value)
      Converts a string to an object. The parsing mechanism is defined by the specific converter. null and empty string are converted to null.
      Parameters:
      value - the String to convert
      Returns:
      an object of type T created from the string passed in
    • toString

      public String toString(LocalDate value)
      Converts an object to a string form. The format of the returned string is defined by the specific converter. null is converted to an empty string, otherwise the type's toString is used.
      Parameters:
      value - the object of type T to convert
      Returns:
      a string representation of the object passed in