I was using TimeUnit.MILLISECONDS.toDays(ms) to convert a millisecond time quantity to days but reading the JavaDoc I noticed it's based on
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.
double days= (double)ms/1000*60*60*24;
Just use TimeUnit the other way round:
double days = ms / (double) TimeUnit.DAYS.toMillis(1);