Given today\'s time e.g. 2:24PM, how do I get it to round to 2:30PM?
Similarly if the time was 2:17PM, how do I get it to round to 2:15PM?
If you just want to round down this is a more readable version using Java Time API:
LocalDateTime time = LocalDateTime.now(); LocalDateTime lastQuarter = time.truncatedTo(ChronoUnit.HOURS) .plusMinutes(15 * (time.getMinute() / 15));
output:
2016-11-04T10:58:10.228
2016-11-04T10:45:00