java - 如何在Java中以人类可读的格式显示时间?

标签 java calendar logic

我正在制定一种逻辑,用一种方法我可以得到以毫秒为单位的时间。 我想展示如下内容:

if time is b/w 1 minutes - 60 minutes, lets say 25 minutes it will show - 25 minute
if time is 1 hour and 59 minutes it will show - 1h+
later if its 2 hour than it will show - 2h+
this will continue to 24 hour.
later if its one day and few hours than it will show - 1d+
this will be continue till week and later on week, months and year like 
    1h+..... 1d,
    1d+..... 1w,
    1w+..... 1m,
    1m+..... 1y, 1y+..

我不能使用更多的 if else 。我需要使用这种方法获得良好的性能。

最佳答案

您可以编写几个 if 并创建毫秒范围的表,例如使用具有键和值的并发 HashMap 。如果您的毫秒范围在 0 到 60000 毫秒之间,请在 HashMap 中创建一个秒键和值,与 60000 到 3600000 类似,在其中创建一个分钟键和值,同样您可以正确的范围及其值。

关于java - 如何在Java中以人类可读的格式显示时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32664901/

相关文章:

java - org.springframework.beans.factory.BeanCreationException : Error creating bean with name 'scriptDataSourceInitializer' defined in class path resources?

android - 查询日历 ICS

python - 为什么 "B"不等于 "B"?

javascript - 我的运算符(operator)出了什么问题? JavaScript

java - 创建 java C :\Program Files\Java\jdk1. 7.0_05\jre\bin\client\jvm.dll 失败

java - 如果未输入有效整数,如何让程序因错误而终止?

android - 自定义日历日期范围滑动选择android

java-8 - Java 8 添加没有时间段的日期

javascript - 当表达式不可能为 TRUE 时,它的计算结果为 TRUE,不是吗?

java - 将数据结构(列表的列表)转换为 Html 表