Class DateTimeStringConverter

java.lang.Object
javafx.util.StringConverter<Date>
javafx.util.converter.DateTimeStringConverter
Direct Known Subclasses:
DateStringConverter, TimeStringConverter

public class DateTimeStringConverter extends StringConverter<Date>

A StringConverter implementation for Date values that represent dates and times. Instances of this class are immutable unless created with the DateTimeStringConverter(DateFormat) constructor (with a non-null argument).

Note that using Date is not recommended in JDK versions where LocalDateTime is available, in which case LocalDateTimeStringConverter should be used.

Since:
JavaFX 2.1
  • Constructor Details

    • DateTimeStringConverter

      public DateTimeStringConverter()
      Creates a DateTimeStringConverter that uses a formatter/parser based on DateFormat.DEFAULT for both date and time styles, and the user's Locale.
    • DateTimeStringConverter

      public DateTimeStringConverter(int dateStyle, int timeStyle)
      Creates a DateTimeStringConverter that uses a formatter/parser based on the given date and time styles, and the user's Locale.
      Parameters:
      dateStyle - the formatting style for dates. For example, DateFormat.SHORT for "M/d/yy" in the US locale.
      timeStyle - the formatting style for times. For example, DateFormat.SHORT for "h:mm a" in the US locale.
      Since:
      JavaFX 8u40
    • DateTimeStringConverter

      public DateTimeStringConverter(Locale locale)
      Creates a DateTimeStringConverter that uses a formatter/parser based on DateFormat.DEFAULT for both date and time styles, and the given Locale.
      Parameters:
      locale - the Locale that will be used by the formatter/parser. If null, the user's locale will be used.
    • DateTimeStringConverter

      public DateTimeStringConverter(Locale locale, int dateStyle, int timeStyle)
      Creates a DateTimeStringConverter that uses a formatter/parser based on the given date and time styles, and Locale.
      Parameters:
      locale - the Locale that will be used by the formatter/parser. If null, the user's locale will be used.
      dateStyle - the formatting style for dates. For example, DateFormat.SHORT for "M/d/yy" in the US locale.
      timeStyle - the formatting style for times. For example, DateFormat.SHORT for "h:mm a" in the US locale.
      Since:
      JavaFX 8u40
    • DateTimeStringConverter

      public DateTimeStringConverter(String pattern)
      Creates a DateTimeStringConverter that uses a formatter/parser based on the given pattern, and the user's Locale.
      Parameters:
      pattern - the pattern describing the date and time format. If null, DateFormat.DEFAULT will be used for both date and time.
    • DateTimeStringConverter

      public DateTimeStringConverter(Locale locale, String pattern)
      Creates a DateTimeStringConverter that uses a formatter/parser based on the given pattern and Locale.
      Parameters:
      locale - the Locale that will be used by the formatter/parser. If null, the user's locale will be used.
      pattern - the pattern describing the date and time format. If null, DateFormat.DEFAULT will be used for both date and time styles.
    • DateTimeStringConverter

      public DateTimeStringConverter(DateFormat dateFormat)
      Creates a DateTimeStringConverter that uses the given formatter/parser.
      Parameters:
      dateFormat - the formatter/parser that will be used by the toString() and fromString() methods. If null, a default formatter/parser will be used.
  • Method Details

    • fromString

      public Date 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(Date 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