Class DurationFormatterUtils
java.lang.Object
org.springframework.format.datetime.standard.DurationFormatterUtils
Support 
Duration parsing and printing in several styles, as listed in
 DurationFormat.Style.
 Some styles may not enforce any unit to be present, defaulting to DurationFormat.Unit#MILLIS
 in that case. Methods in this class offer overloads that take a DurationFormat.Unit to
 be used as a fall-back instead of the ultimate MILLIS default.
- Since:
- 6.2
- Author:
- Phillip Webb, Valentine Wu, Simon Baslé
- 
Method SummaryModifier and TypeMethodDescriptionstatic DurationFormat.StyleDetect the style from the given source value.static DurationdetectAndParse(String value) Detect the style then parse the value to return a duration.static DurationdetectAndParse(String value, @Nullable DurationFormat.Unit unit) Detect the style then parse the value to return a duration.static Durationparse(String value, DurationFormat.Style style) Parse the given value to a duration.static Durationparse(String value, DurationFormat.Style style, @Nullable DurationFormat.Unit unit) Parse the given value to a duration.static Stringprint(Duration value, DurationFormat.Style style) Print the specified duration in the specified style.static Stringprint(Duration value, DurationFormat.Style style, @Nullable DurationFormat.Unit unit) Print the specified duration in the specified style using the given unit.
- 
Method Details- 
parseParse the given value to a duration.- Parameters:
- value- the value to parse
- style- the style in which to parse
- Returns:
- a duration
 
- 
parsepublic static Duration parse(String value, DurationFormat.Style style, @Nullable DurationFormat.Unit unit) Parse the given value to a duration.- Parameters:
- value- the value to parse
- style- the style in which to parse
- unit- the duration unit to use if the value doesn't specify one (- nullwill default to ms)
- Returns:
- a duration
 
- 
printPrint the specified duration in the specified style.- Parameters:
- value- the value to print
- style- the style to print in
- Returns:
- the printed result
 
- 
printpublic static String print(Duration value, DurationFormat.Style style, @Nullable DurationFormat.Unit unit) Print the specified duration in the specified style using the given unit.- Parameters:
- value- the value to print
- style- the style to print in
- unit- the unit to use for printing, if relevant (- nullwill default to ms)
- Returns:
- the printed result
 
- 
detectAndParseDetect the style then parse the value to return a duration.- Parameters:
- value- the value to parse
- Returns:
- the parsed duration
- Throws:
- IllegalArgumentException- if the value is not a known style or cannot be parsed
 
- 
detectAndParseDetect the style then parse the value to return a duration.- Parameters:
- value- the value to parse
- unit- the duration unit to use if the value doesn't specify one (- nullwill default to ms)
- Returns:
- the parsed duration
- Throws:
- IllegalArgumentException- if the value is not a known style or cannot be parsed
 
- 
detectDetect the style from the given source value.- Parameters:
- value- the source value
- Returns:
- the duration style
- Throws:
- IllegalArgumentException- if the value is not a known style
 
 
-