开发者

Format a period with DurationFormatUtils in a nice way

开发者 https://www.devze.com 2022-12-28 12:54 出处:网络
This works very well: out.println(DurationFormatUtils.formatPeriod( new Date().getTime(), match.getStartingTime().getTime(),

This works very well:

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

But now I would like to have some nicer format

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

But as aspected this gives output as

45 a01101 4 hour1101 left

开发者_运维知识库

Is there a simple solution for this problem?


It would appear that they base their formatting on the SimpleDateFormatter and the escape character there is '

So your code would be something like this:

"d 'days' H 'hours left'"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号