public class LocalDateTimeStringConverter extends StringConverter<LocalDateTime>
StringConverter
implementation for LocalDateTime
values.
LocalDateStringConverter
,
LocalTimeStringConverter
Constructor and Description |
---|
LocalDateTimeStringConverter()
Create a
StringConverter for LocalDateTime values, using a
default formatter and parser based on IsoChronology ,
FormatStyle.SHORT for both date and time, and the user's
Locale . |
LocalDateTimeStringConverter(DateTimeFormatter formatter,
DateTimeFormatter parser)
Create a
StringConverter for LocalDateTime values using
the supplied formatter and parser. |
LocalDateTimeStringConverter(FormatStyle dateStyle,
FormatStyle timeStyle)
Create a
StringConverter for LocalDateTime values, using
a default formatter and parser based on IsoChronology , the
specified FormatStyle values for date and time, and the user's
Locale . |
LocalDateTimeStringConverter(FormatStyle dateStyle,
FormatStyle timeStyle,
Locale locale,
Chronology chronology)
Create a
StringConverter for LocalDateTime values using a
default formatter and parser, which will be based on the supplied
FormatStyle s, Locale , and Chronology . |
Modifier and Type | Method and Description |
---|---|
LocalDateTime |
fromString(String value)
Converts the string provided into an object defined by the specific converter.
|
String |
toString(LocalDateTime value)
Converts the object provided into its string form.
|
public LocalDateTimeStringConverter()
StringConverter
for LocalDateTime
values, using a
default formatter and parser based on IsoChronology
,
FormatStyle.SHORT
for both date and time, and the user's
Locale
.
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.
public LocalDateTimeStringConverter(FormatStyle dateStyle, FormatStyle timeStyle)
StringConverter
for LocalDateTime
values, using
a default formatter and parser based on IsoChronology
, the
specified FormatStyle
values for date and time, and the user's
Locale
.dateStyle
- The FormatStyle
that will be used by the default
formatter and parser for the date. If null then FormatStyle.SHORT
will be used.timeStyle
- The FormatStyle
that will be used by the default
formatter and parser for the time. If null then FormatStyle.SHORT
will be used.public LocalDateTimeStringConverter(DateTimeFormatter formatter, DateTimeFormatter parser)
StringConverter
for LocalDateTime
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); StringConverterconverter = DateTimeStringConverter.getLocalDateTimeConverter(formatter, null);
Locale
and Chronology
as needed.formatter
- An instance of DateTimeFormatter
which will be
used for formatting by the toString() method. If null then a default
formatter will be used.parser
- An instance of DateTimeFormatter
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.public LocalDateTimeStringConverter(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale, Chronology chronology)
StringConverter
for LocalDateTime
values using a
default formatter and parser, which will be based on the supplied
FormatStyle
s, Locale
, and Chronology
.dateStyle
- The FormatStyle
that will be used by the default
formatter and parser for the date. If null then FormatStyle.SHORT
will be used.timeStyle
- The FormatStyle
that will be used by the default
formatter and parser for the time. If null then FormatStyle.SHORT
will be used.locale
- The Locale
that will be used by the
default formatter and parser. If null then
Locale.getDefault(Locale.Category.FORMAT)
will be used.chronology
- The Chronology
that will be used by the default
formatter and parser. If null then IsoChronology.INSTANCE
will be
used.public LocalDateTime fromString(String value)
fromString
in class StringConverter<LocalDateTime>
public String toString(LocalDateTime value)
toString
in class StringConverter<LocalDateTime>
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2008, 2017, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.