Class DurationFormatter
java.lang.Object
org.springframework.format.datetime.standard.DurationFormatter
Formatter
implementation for a JSR-310 Duration
,
following JSR-310's parsing rules for a Duration by default and
supporting additional DurationFormat.Style
styles.- Since:
- 6.2
- Author:
- Juergen Hoeller
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate aDurationFormatter
in a specificDurationFormat.Style
.DurationFormatter
(DurationFormat.Style style, DurationFormat.Unit defaultUnit) -
Method Summary
-
Constructor Details
-
DurationFormatter
Create aDurationFormatter
in a specificDurationFormat.Style
.When a unit is needed but cannot be determined (e.g. printing a Duration in the
SIMPLE
style),DurationFormat.Unit#MILLIS
is used. -
DurationFormatter
Create aDurationFormatter
in a specificDurationFormat.Style
with an optionalDurationFormat.Unit
.If a
defaultUnit
is specified, it may be used in parsing cases when no unit is present in the string (provided the style allows for such a case). It will also be used as the representation's resolution when printing in theDurationFormat.Style.SIMPLE
style. Otherwise, the style defines its default unit.- Parameters:
style
- theDurationStyle
to usedefaultUnit
- theDurationFormat.Unit
to fall back to when parsing and printing
-
-
Method Details
-
parse
Description copied from interface:Parser
Parse a text String to produce a T.- Specified by:
parse
in interfaceParser<Duration>
- Parameters:
text
- the text stringlocale
- the current user locale- Returns:
- an instance of T
- Throws:
ParseException
- when a parse exception occurs in a java.text parsing library
-
print
Description copied from interface:Printer
Print the object of type T for display.
-