Adding or subtracting time to/from Instant

For adding time, Instant has a suite of methods. For example, adding 2 hours to the current timestamp can be accomplished as follows:

Instant twoHourLater = Instant.now().plus(2, ChronoUnit.HOURS);

In terms of subtracting time, for example, 10 minutes, use the following code snippet:

Instant tenMinutesEarlier = Instant.now()
.minus(10, ChronoUnit.MINUTES);
Beside the plus() method, Instant also contains plusNanos(), plusMillis(), and plusSeconds(). Moreover, beside the minus() method, Instant also contains minusNanos(), minusMillis(), and  minusSeconds().
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.237.201