I spent all the morning trying to find out a way to achieve what I initially thought would be an relatively easy task: convert a duration of time expressed in a numeric way into a readable way. For example, for an input of 3.5, the output should be "3 years and 6 months".
According to what I was reading, it seems that Joda Time library is strongly recommended. Using that library and following this post I was trying things like:
Period p = new Period(110451600000L); // 3 years and a half
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendYears()
.appendSuffix(" year", " years")
.appendSeparator(" and ")
.appendMonths()
.appendSuffix(" month", " months")
.toFormatter();
System.out.println(formatter.print(p));
But the output is nothing. No idea why it's not working.
I also tried with the Apache DurationFormatUtils, but doesn't work.
Does anybody have an idea?
Thanks in advance.