StringConverter
implementation for LocalDateTime
values.
- Since:
- JavaFX 8u40
- See Also:
-
Constructor Summary
ConstructorDescriptionCreate aStringConverter
forLocalDateTime
values, using a default formatter and parser based onIsoChronology
,FormatStyle.SHORT
for both date and time, and the user'sLocale
.LocalDateTimeStringConverter
(DateTimeFormatter formatter, DateTimeFormatter parser) Create aStringConverter
forLocalDateTime
values using the supplied formatter and parser.LocalDateTimeStringConverter
(FormatStyle dateStyle, FormatStyle timeStyle) Create aStringConverter
forLocalDateTime
values, using a default formatter and parser based onIsoChronology
, the specifiedFormatStyle
values for date and time, and the user'sLocale
.LocalDateTimeStringConverter
(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale, Chronology chronology) Create aStringConverter
forLocalDateTime
values using a default formatter and parser, which will be based on the suppliedFormatStyle
s,Locale
, andChronology
. -
Method Summary
Modifier and TypeMethodDescriptionfromString
(String value) Converts the string provided into an object defined by the specific converter.toString
(LocalDateTime value) Converts the object provided into its string form.
-
Constructor Details
-
LocalDateTimeStringConverter
public LocalDateTimeStringConverter()Create aStringConverter
forLocalDateTime
values, using a default formatter and parser based onIsoChronology
,FormatStyle.SHORT
for 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
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 as expected in these locales. -
LocalDateTimeStringConverter
Create aStringConverter
forLocalDateTime
values, using a default formatter and parser based onIsoChronology
, the specifiedFormatStyle
values for date and time, and the user'sLocale
.- Parameters:
dateStyle
- TheFormatStyle
that will be used by the default formatter and parser for the date. If null thenFormatStyle.SHORT
will be used.timeStyle
- TheFormatStyle
that will be used by the default formatter and parser for the time. If null thenFormatStyle.SHORT
will be used.
-
LocalDateTimeStringConverter
Create aStringConverter
forLocalDateTime
values 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<LocalDateTime> converter = DateTimeStringConverter.getLocalDateTimeConverter(formatter, null);
Locale
andChronology
as needed.- Parameters:
formatter
- An instance ofDateTimeFormatter
which will be used for formatting by the toString() method. If null then a default formatter will be used.parser
- An instance ofDateTimeFormatter
which will be used for parsing by the fromString() method. This can be identical to formatter. If null then formatter will be used, and if that is also null, then a default parser will be used.
-
LocalDateTimeStringConverter
public LocalDateTimeStringConverter(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale, Chronology chronology) Create aStringConverter
forLocalDateTime
values using a default formatter and parser, which will be based on the suppliedFormatStyle
s,Locale
, andChronology
.- Parameters:
dateStyle
- TheFormatStyle
that will be used by the default formatter and parser for the date. If null thenFormatStyle.SHORT
will be used.timeStyle
- TheFormatStyle
that will be used by the default formatter and parser for the time. If null thenFormatStyle.SHORT
will be used.locale
- TheLocale
that will be used by the default formatter and parser. If null thenLocale.getDefault(Locale.Category.FORMAT)
will be used.chronology
- TheChronology
that will be used by the default formatter and parser. If null thenIsoChronology.INSTANCE
will be used.
-
-
Method Details
-
fromString
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:
fromString
in classStringConverter<LocalDateTime>
- Parameters:
value
- theString
to convert- Returns:
- an object representation of the string passed in.
-
toString
Converts the object provided into its string form. Format of the returned string is defined by the specific converter.- Specified by:
toString
in classStringConverter<LocalDateTime>
- Parameters:
value
- the object of typeT
to convert- Returns:
- a string representation of the object passed in
-