Which statement is true about java.time.Duration?
Click on the arrows to vote for the correct answer
A. B. C. D.C.
http://tutorials.jenkov.com/java-date-time/duration.html#accessing-the-time-of-a-durationThe correct answer is C. It defines time-based values.
The java.time.Duration
class is part of the java.time
package introduced in Java 8 as part of the new date/time API. It represents a duration of time in seconds and nanoseconds. It is used to represent the amount of time between two temporal objects such as LocalDateTime
or Instant
.
Option A is incorrect because Duration
does not track time zones. Instead, it represents a duration of time independent of any time zone.
Option B is also incorrect because Duration
does not preserve daylight saving time. It represents a fixed duration of time that does not change based on daylight saving time.
Option D is also incorrect because Duration
is not used to represent date-based values. Instead, it is used to represent time-based values, such as the amount of time between two temporal objects.
To create an instance of Duration
, you can use one of the factory methods provided by the class, such as Duration.ofSeconds(long seconds)
or Duration.ofMinutes(long minutes)
. Once you have an instance of Duration
, you can perform operations on it, such as adding or subtracting it from a temporal object.
Overall, java.time.Duration
is a useful class for representing and manipulating time-based durations in Java 8 and later versions.