I write some piece of code in Java 8 which use time arithmetic. I realize that I can implement in differentways. Lets look at simple code below. Of course it is the same result
If you look at the source, the plus(long amountToAdd, TemporalUnit unit)
method uses the plusXXX
methods to produce the results. So there are no arguments here about efficiency.
Instead, you use whichever is most appropriate for your scenario. I would suggest that if you are using user input to decide whether to add hours, minutes, etc., then the plus()
method is better. Otherwise, your code might be easier to read if you use plusXXX
.