Class LocalTimeStringConverter

java.lang.Object
javafx.util.StringConverter<LocalTime>
javafx.util.converter.LocalTimeStringConverter

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

    • LocalTimeStringConverter

      public LocalTimeStringConverter()
      Creates a LocalTimeStringConverter that uses a formatter and parser based on FormatStyle.SHORT, and the user's Locale.
    • LocalTimeStringConverter

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

      public LocalTimeStringConverter(FormatStyle timeStyle, Locale locale)
      Creates a LocalTimeStringConverter that uses a formatter and parser based on the specified FormatStyle and Locale.
      Parameters:
      timeStyle - 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.
    • LocalTimeStringConverter

      public LocalTimeStringConverter(DateTimeFormatter formatter, DateTimeFormatter parser)

      Creates a LocalTimeStringConverter that uses the given formatter and parser.

      For example, a fixed pattern can be used for converting both ways:

      String pattern = "HH:mm:ss";
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
      StringConverter<LocalTime> converter = DateTimeStringConverter.getLocalTimeConverter(formatter, null);
      
      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 LocalTime 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(LocalTime 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