You can use the lambda functional programming streams approach to make this a one liner.
Add a second and truncate. To cover the corner case of being exactly on a second, check the truncated to the original, and only add a second if they differ:
Instant myRoundedUpInstant = Optional.of(myInstant.truncatedTo(ChronoUnit.SECONDS))
.filter(myInstant::equals)
.orElse(myInstant.truncatedTo(ChronoUnit.SECONDS).plusSeconds(1));
See this code run line at IdeOne.com.
Instant.toString(): 2019-07-30T20:06:33.456424Z
myRoundedUpInstant(): 2019-07-30T20:06:34Z
…and…
myInstant.toString(): 2019-07-30T20:05:20Z
myRoundedUpInstant(): 2019-07-30T20:05:20Z
Or alternatively, with a slightly different approach:
Instant myRoundedUpInstant = Optional.of(myInstant)
.filter(t -> t.getNano() != 0)
.map(t -> t.truncatedTo(ChronoUnit.SECONDS).plusSeconds(1))
.orElse(myInstant);
See this code run live at IdeOne.com.
myInstant.toString(): 2019-07-30T20:09:07.415043Z
myRoundedUpInstant(): 2019-07-30T20:09:08Z
…and…
myInstant.toString(): 2019-07-30T19:44:06Z
myRoundedUpInstant(): 2019-07-30T19:44:06Z
Above is of course in Java 8 land. I'll leave it as an exercise to the reader to split that out into the more traditional if/else if Optional
isn't your thing :-)