Java Duration Pitfall

Опубликовано: 15 Апрель 2026
на канале: The Self-Taught Software Engineer
215
13

Do you want to learn Java? Then you are absolutely right in this short tutorial:

In today's episode of ByteSized, we are looking at something to be cautious about when using the `Duration` class in Java (out of the `java.time` package). It does make a big difference in which order you pass in the arguments to `Duration.between`.
By default, if the first argument is a date time that is further in the future than the second one, the resulting `Duration` will be a negative value, which is seldom what one is looking for. To fix this, you can use the `.abs()` method on a constructed `Duration` to receive the total, absolute value.

#Java #Tutorial #Guide #Shorts

If you have any suggestions for content or feedback please leave them in the comments.

In case you enjoyed this video, make sure to leave like, subscribe and share it with anyone you could consider interested!