In these lines:
final long MICRO_PER_DAY=24 * 60 * 60 * 1000 * 1000;
final long MILLIS_PER_DAY= 24 * 60 * 60 * 1000;
each of the constant integer numbers is of type int
and the result calculated is also of type int
.
But the result you would expect: 86400000000
for MICRO_PER_DAY
is too large to fit in the 32 bits of an int
and it is truncated.
This is called Numeric Overflow.
To get the right result use this:
final long MICRO_PER_DAY=24L * 60 * 60 * 1000 * 1000;
final long MILLIS_PER_DAY= 24L * 60 * 60 * 1000;
The L
suffix after 24
will guide the compiler so that it does store the result in the 64 bits of type long
and not truncate it.