有没有办法在不损失精度的情况下获得毫秒到天的转换而无需在Java中编写数学公式?

Is there a way to obtain a milliseconds to days conversion without losing precision and without the need to write the mathematical formula in Java?

我使用 TimeUnit.MILLISECONDS.toDays(ms) 将毫秒时间量转换为天数,但在阅读 JavaDoc 时我注意到它基于 .convert() 并失去了精度

Convert the given time duration in the given unit to this unit. Conversions from finer to coarser granularities truncate, so lose precision. For example converting 999 milliseconds to seconds results in 0. Conversions from coarser to finer granularities with arguments that would numerically overflow saturate to Long.MIN_VALUE if negative or Long.MAX_VALUE if positive.

真没想到,我的5分钟(300000ms)变成了0天。直接的解决方案是写这个

double days= (double)ms/1000*60*60*24;

这很糟糕,我认为没有必要,但它确实有效。有什么建议吗?还有其他我可以使用的功能吗?

ps:我不是在等你告诉我应该将这些数字放入静态变量中,我是想了解什么样的解决方案才是好的解决方案。提前致谢

反过来使用 TimeUnit:

double days = ms / (double) TimeUnit.DAYS.toMillis(1);