사용 5 분 다음 여러 방향으로 라운드 할 수 있습니다
LocalDateTime dt = …
dt = dt.withSecond(0).withNano(0).plusMinutes((65-dt.getMinute())%5);
당신은 사용하여 예를 재현 할 수있는이 예에서는
LocalDateTime dt=LocalDateTime.now().withHour(16).withSecond(0).withNano(0);
for(int i=1; i<=10; i++) {
dt=dt.withMinute(i);
System.out.printf("%02d%02d -> ", dt.getHour(), dt.getMinute());
// the rounding step:
dt=dt.plusMinutes((65-dt.getMinute())%5);
System.out.printf("%02d%02d%n", dt.getHour(), dt.getMinute());
}
→
1601 -> 1605
1602 -> 1605
1603 -> 1605
1604 -> 1605
1605 -> 1605
1606 -> 1610
1607 -> 1610
1608 -> 1610
1609 -> 1610
1610 -> 1610
(I 그들이 0으로 유지되면 초와 나노를 한 번만 지우십시오).
[관련] (https://stackoverflow.com/questions/25552023/round-minutes-to-ceiling-using-java-8 : 당신이 원하는 경우에 조정의 끝을 수정할 수 있습니다) 중복되지는 않지만. 즉, 분을 잘라내어 올바른 숫자를 다시 추가하십시오. –
관련 항목 http://stackoverflow.com/questions/3553964/how-to-round-time-to-the-nearest-quarter-hour-in-java – Tunaki
당신은 다음 라운드로 돌리시겠습니까? 질문의 본문에 명시된대로 제목과 예제가 제안하거나 * 가장 가까운 * 이름으로 표시됩니다. – Holger