How to round off to the closest 5 minute interval if it is 1 or 2 minutes ahead or behind?

I want to round off an Instant / LocalDateTime to its closest 5 minutes interval in Java. Examples: Suppose the time is: 2021-02-08T19:02:49.594 Expected result: 2021-02-08T19:00:00.000 Suppose the …