Format a period with DurationFormatUtils in a beautiful way

This works very well:

out.println(DurationFormatUtils.formatPeriod(
                        new Date().getTime(),
                        match.getStartingTime().getTime(),
                        "d H"));

But now I would like to have a more pleasant format

out.println(DurationFormatUtils.formatPeriod(
                        new Date().getTime(),
                        match.getStartingTime().getTime(),
                        "d days H hours left"));

But as an aspect, this gives the result as

45 a01101 4 hours1101 left

Is there a simple solution to this problem?

+3
source share
1 answer

It looks like they base their formatting on SimpleDateFormatter , and the escape character is

So your code would be something like this:

"d 'days' H 'hours left'"
+14
source

Source: https://habr.com/ru/post/1742961/


All Articles