开发者

Clean toString from JodaTime Period

开发者 https://www.devze.com 2023-01-24 18:37 出处:网络
I\'m calling toString() (or difference.normalizedStandard().toString()) on a Period object, and getting \"PT-10H0.317S\"

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消