PeriodFormatter - 如果小时或分钟恰好是一位数字,如何预置0?

Aha*_*med 4 java formatting period jodatime

当我使用PeriodFormatter如下

PeriodFormatter formatter = new PeriodFormatterBuilder().appendHours()
                .appendLiteral(":").appendMinutes().appendLiteral(":")
                .appendSeconds().toFormatter();
Run Code Online (Sandbox Code Playgroud)

我得到了输出,4:39:9这意味着4小时39分钟和9秒.

如何修改格式化程序来生成04:39:09?谢谢

Jua*_*ado 14

添加.printZeroAlways()和.minimumPrintedDigits(2):

    PeriodFormatter formatter = new PeriodFormatterBuilder()
        .printZeroAlways()
        .minimumPrintedDigits(2)
        .appendHours()
        .appendLiteral(":")
        .appendMinutes()
        .appendLiteral(":")
        .appendSeconds()
        .toFormatter();
Run Code Online (Sandbox Code Playgroud)