Class LocalDateTimeStringConverter
- javafx.util.StringConverter<LocalDateTime>
-
- javafx.util.converter.LocalDateTimeStringConverter
public class LocalDateTimeStringConverter extends StringConverter<LocalDateTime>
StringConverter implementation for LocalDateTime values.
Since:
JavaFX 8u40
See Also:
-
Constructor Summary
Constructors Constructor and Description LocalDateTimeStringConverter()Create aStringConverterforLocalDateTimevalues, using a default formatter and parser based onIsoChronology,FormatStyle.SHORTfor both date and time, and the user'sLocale.LocalDateTimeStringConverter(DateTimeFormatter formatter, DateTimeFormatter parser)Create aStringConverterforLocalDateTimevalues using the supplied formatter and parser.LocalDateTimeStringConverter(FormatStyle dateStyle, FormatStyle timeStyle)Create aStringConverterforLocalDateTimevalues, using a default formatter and parser based onIsoChronology, the specifiedFormatStylevalues for date and time, and the user'sLocale.LocalDateTimeStringConverter(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale, Chronology chronology)Create aStringConverterforLocalDateTimevalues using a default formatter and parser, which will be based on the suppliedFormatStyles,Locale, andChronology.
-
Method Summary
All MethodsInstance MethodsConcrete Methods Modifier and Type Method and Description LocalDateTimefromString(String value)Converts the string provided into an object defined by the specific converter.StringtoString(LocalDateTime value)Converts the object provided into its string form.
-
Constructor Detail
-
LocalDateTimeStringConverter
public LocalDateTimeStringConverter()
Create aStringConverterforLocalDateTimevalues, using a default formatter and parser based onIsoChronology,FormatStyle.SHORTfor both date and time, and the user'sLocale.This converter ensures symmetry between the toString() and fromString() methods. Many of the default locale based patterns used by
DateTimeFormatterwill 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
public LocalDateTimeStringConverter(FormatStyle dateStyle, FormatStyle timeStyle)Create aStringConverterforLocalDateTimevalues, using a default formatter and parser based onIsoChronology, the specifiedFormatStylevalues for date and time, and the user'sLocale.Parameters:
dateStyle- TheFormatStylethat will be used by the default formatter and parser for the date. If null thenFormatStyle.SHORTwill be used.
-
LocalDateTimeStringConverter
public LocalDateTimeStringConverter(DateTimeFormatter formatter, DateTimeFormatter parser)Create aStringConverterforLocalDateTimevalues using the supplied formatter and parser.For example, to use a fixed pattern for converting both ways:
Note that the formatter and parser can be created to handle non-defaultString pattern = "yyyy-MM-dd HH:mm"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); StringConverter converter = DateTimeStringConverter.getLocalDateTimeConverter(formatter, null);LocaleandChronologyas needed.Parameters:
formatter- An instance ofDateTimeFormatterwhich will be used for formatting by the toString() method. If null then a default formatter will be used.
-
LocalDateTimeStringConverter
public LocalDateTimeStringConverter(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale, Chronology chronology)Create aStringConverterforLocalDateTimevalues using a default formatter and parser, which will be based on the suppliedFormatStyles,Locale, andChronology.Parameters:
dateStyle- TheFormatStylethat will be used by the default formatter and parser for the date. If null thenFormatStyle.SHORTwill be used.
-
-
Method Detail
-
fromString
public LocalDateTime fromString(String value)
Converts the string provided into an object defined by the specific converter. Format of the string and type of the resulting object is defined by the specific converter.Specified by:
fromStringin classStringConverter<LocalDateTime>Returns:
an object representation of the string passed in.
-
toString
public String toString(LocalDateTime value)
Converts the object provided into its string form. Format of the returned string is defined by the specific converter.Specified by:
toStringin classStringConverter<LocalDateTime>Returns:
a string representation of the object passed in.
-
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.