Java 8 / java.time solution
As an alternative to TimeUnit for some reason you might prefer the Duration class from the java.time package:
Duration.ofDays(1).getSeconds() // returns 86400; Duration.ofMinutes(1).getSeconds(); // 60 Duration.ofHours(1).toMinutes(); // also 60 //etc.
In addition, if you go deeper and analyze how the Duration.ofDays (..) method works, you will see the following code:
return create(Math.multiplyExact(days, SECONDS_PER_DAY), 0);
where SECONDS_PER_DAY is the static constant protected by the package from the LocalTime class.
static final int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;
I think it is safe to assume that if there is some package that defines "all annoying time constants, such as miliseconds / seconds / minutes", as you call them, I believe that the Java SDK developers would use them .
Why is this package of LocalTime constants protected and not publicly available, this is a good question, I think there is a reason for this. At the moment, it looks like you really need to copy them and maintain them yourself.
Mateusz Szulc Feb 01 '16 at 10:26 2016-02-01 10:26
source share