Is there way to convert ‘x’ seconds to y hours and z seconds when say x exceeds 3600 seconds? Similarly, convert it to ‘a minutes and b seconds’ when x exceeds 60 but is less than 3600 seconds, using JodaTime? I understand that I would have to specify what I need in the PeriodFormatter, but I don’t want to specify it – I want a formatted text based on value of seconds.
This is similar to how you would post on a forum and then your post will initially be shown as ‘posted 10 seconds ago’.. after 1 minute you would see ‘posted 1minute 20 seconds ago’ and likewise for weeks,days,years.
I’m not sure why you don’t want to specify what you need in
PeriodFormatter.JodaTimedoesn’t know how you want to display a period as a string, so you need to tell it via thePeriodFormatter.As 3600 seconds is 1 hour, using the formatter properly will automatically do this for you. Here’s a code example using a number of different inputs on the same formatter which should achieve your desired result.
Produces output::