我正在制定一种逻辑,用一种方法我可以得到以毫秒为单位的时间。 我想展示如下内容:
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/