簡體   English   中英

jodaTime PeriodFormatter無法正確格式化

[英]jodaTime PeriodFormatter not formatting correctly

我有這個PeriodFormatter:

PeriodFormatterBuilder()
            .appendDays()
            .appendSuffix(
                " day",
                " days")
            )
            .appendSeparator(", ")
            .printZeroRarelyLast()
            .appendHours()
            .appendSuffix(
                " hours",
                " hours"
            )
            .appendSeparator(" ")
            .appendMinutes()
            .appendSuffix(" minute")
            .toFormatter()
            .let {
                Period(Seconds.seconds(seconds.toInt())).toString(it)
            }

我想輸入幾秒鍾,並獲得x天,x小時,x分鍾。...執行此操作時,我得到一個空字符串。 如果我將“ appendSeconds()”添加到格式化程序創建中,則返回的秒數將與發送的返回值相同。

我需要轉換,而不僅是金額,而且我對秒數不感興趣,而對轉換所需的時間,分鍾和小時感興趣。有誰可以幫助您?

您需要使用Period.normalizedStandard()來說服您的時間段,以將秒轉換為分鍾,小時和天。

            Period(Seconds.seconds(seconds.toInt())).normalizedStandard().toString(it)

(不確定Kotlin中是否需要空的圓括號() 。它們在我測試過的Java中。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM