.Yes.
Calendar.getInstance().get(Calendar.MINUTE)
returns the current minute count within the hour.
To find the nearest 10 min, assuming minutes
contains the current minute count, you do:
int nearest = ((minutes+5) / 10)*10 % 60;
It uses integer division by 10 to “round down” to nearest 10, but first 5 is added such that 25 becomes 30, then divided by 10 becomes 3, then multiplied by 3 becomes 30.
Lastly modulus 60 because otherwise 56 minutes would be rounded to 60 which you cannot have.
The whole math part of the last formula is the same as is often used to round decimal numbers (add 0.5, then truncate it to whole integer – if it was 0.5 or more to start with then adding 0.5 gives 1 or more to ensure it rounds up when appropriate).
3
solved Java timestamps. checking if near time, it is the time or over [closed]