Duration can handle periods of fixed length, such as hours, minutes, seconds, days (where it takes exactly 24 hours a day). You cannot use βmonthsβ with Duration because the month varies in length.
Period - another common implementation of TemporalAmount - represents years, months and days separately.
Personally, I would recommend:
- When you know the device in advance, use the appropriate
plusXxx method, for example. time.plusMinutes(10) . It is about as easy to read as it turns out. - When you try to present the βlogicalβ amounts of a calendar, use
Period - When you are trying to represent fixed-length amounts, use
Duration
Here is an example of where Period and Duration may differ:
import java.time.*; public class Test { public static void main(String[] args) { ZoneId zone = ZoneId.of("Europe/London");
I would not worry about efficiency until you need it - at this point you should have a standard so that you can test various parameters.
Jon skeet
source share