Class LocalDateTimeStringConverter
StringConverter implementation for LocalDateTime values.- Since:
- JavaFX 8u40
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates aLocalDateTimeStringConverterthat uses a formatter and parser based onIsoChronology,FormatStyle.SHORTfor both date and time, and the user'sLocale.LocalDateTimeStringConverter(DateTimeFormatter formatter, DateTimeFormatter parser) Creates aLocalDateTimeStringConverterthat uses the given formatter and parser.LocalDateTimeStringConverter(FormatStyle dateStyle, FormatStyle timeStyle) Creates aLocalDateTimeStringConverterthat uses a formatter and parser based onIsoChronology, the givenFormatStylevalues for date and time, and the user'sLocale.LocalDateTimeStringConverter(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale, Chronology chronology) Creates aLocalDateTimeStringConverterthat uses a formatter and parser based on the givenFormatStyles,Locale, andChronology. -
Method Summary
Modifier and TypeMethodDescriptionfromString(String value) Converts a string to an object.toString(LocalDateTime value) Converts an object to a string form.
-
Constructor Details
-
LocalDateTimeStringConverter
public LocalDateTimeStringConverter()Creates a
LocalDateTimeStringConverterthat uses a formatter and parser based onIsoChronology,FormatStyle.SHORTfor both date and time, and the user'sLocale.This converter ensures symmetry between the
toString()andfromString()methods. Many of the default locale based patterns used byDateTimeFormatterwill 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 as expected in these locales. -
LocalDateTimeStringConverter
Creates aLocalDateTimeStringConverterthat uses a formatter and parser based onIsoChronology, the givenFormatStylevalues for date and time, and the user'sLocale.- Parameters:
dateStyle- theFormatStylethat will be used by the formatter and parser for the date. Ifnull,FormatStyle.SHORTwill be used.timeStyle- theFormatStylethat will be used by the formatter and parser for the time. Ifnull,FormatStyle.SHORTwill be used.
-
LocalDateTimeStringConverter
public LocalDateTimeStringConverter(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale, Chronology chronology) Creates aLocalDateTimeStringConverterthat uses a formatter and parser based on the givenFormatStyles,Locale, andChronology.- Parameters:
dateStyle- theFormatStylethat will be used by the formatter and parser for the date. Ifnull,FormatStyle.SHORTwill be used.timeStyle- theFormatStylethat will be used by the formatter and parser for the time. Ifnull,FormatStyle.SHORTwill be used.locale- theLocalethat will be used by the formatter and parser. Ifnull, the user's locale will be used.chronology- theChronologythat will be used by the formatter and parser. Ifnull,IsoChronology.INSTANCEwill be used.
-
LocalDateTimeStringConverter
Creates a
LocalDateTimeStringConverterthat uses the given formatter and parser.For example, to use a fixed pattern for converting both ways:
String pattern = "yyyy-MM-dd HH:mm"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); StringConverter<LocalDateTime> converter = DateTimeStringConverter.getLocalDateTimeConverter(formatter, null);Note that the formatter and parser can be created to handle non-default
LocaleandChronologyas needed.- Parameters:
formatter- the formatter that will be used by thetoString()method. Ifnull, a default formatter will be used.parser- the parser that will be used by thefromString()method. This can be identical to formatter. Ifnull,formatterwill be used, and if that is alsonull, a default parser will be used.
-
-
Method Details
-
fromString
Converts a string to an object. The parsing mechanism is defined by the specific converter.nulland empty string are converted tonull.- Parameters:
value- theStringto convert- Returns:
- an object of type
Tcreated from the string passed in
-
toString
Converts an object to a string form. The format of the returned string is defined by the specific converter.nullis converted to an empty string, otherwise the type'stoStringis used.- Parameters:
value- the object of typeTto convert- Returns:
- a string representation of the object passed in
-