0

I have this 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)
            }

I want to give seconds as input and get x DAYS, x HOURS, x MINUTES back.... I get an empty String back when doing this. If i add "appendSeconds()" to the formatter creation I get the same amount of seconds back as a return value as I sent in..

I need the conversion, not just the amount, and I'm not interested in number of seconds, but how many minutes, hours and days it accounts to.. Anyone who can help?

André
  • 143
  • 1
  • 14
  • Similar: [Convert seconds to years/days/hours/minutes automatically, using JodaTime?](https://stackoverflow.com/questions/10891762/convert-seconds-to-years-days-hours-minutes-automatically-using-jodatime) – Ole V.V. May 27 '18 at 10:45

1 Answers1

1

You need to use Period.normalizedStandard() to persuade your period to convert your seconds into minutes, hours and days.

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

(Not sure whether the empty round brackets () are needed in Kotlin. They are in Java, where I tested.)

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161