Clean toString from JodaTime Period
I'm calling toString() (or difference.normalizedStandard().toString()) on a Period object, and getting "PT-10H0.317S
"
Why is the default toString so inconvenient? What doe开发者_开发技巧s this string even mean?
The period toString is defined in AbstractPeriod#toString()
, which delegates to ISOPeriodFormat
. Here's the JavaDoc:
/**
* The standard ISO format - PyYmMwWdDThHmMsS.
* Milliseconds are not output.
* Note that the ISO8601 standard actually indicates weeks should not
* be shown if any other field is present and vice versa.
*
* @return the formatter
*/
...so apparently it's the ISO 8601 standard format for periods of time. To take manual control of the output, use org.joda.time.format.PeriodFormatterBuilder
.
精彩评论