I am using a countdown using Joda Time. I only need the accuracy of the display of seconds.
However, when printing the time, seconds are displayed as full seconds, so when the countdown reaches, for example, 900 ms, then “0” seconds are printed, but as a countdown it makes sense to display “1” seconds until the time reaches 0 ms.
Example:
void printDuration(Duration d) {
System.out.println(
d.toPeriod(PeriodType.time()).toString(
new PeriodFormatterBuilder().printZeroAlways().appendSeconds().toFormatter()
)
);
}
printDuration(new Duration(5000));
printDuration(new Duration(4900));
printDuration(new Duration(1000));
printDuration(new Duration(900));
printDuration(new Duration(0));
Basically, I need the seconds to be displayed rounded from milliseconds and not rounded. Is there a way to achieve this with Joda without requiring you to write your own formatter?
source
share