- java.time - Discussion
- java.time - Month
- java.time - ZoneOffset
- java.time - ZoneId
- java.time - ZonedDateTime
- java.time - YearMonth
- java.time - Year
- java.time - Period
- java.time - OffsetTime
- java.time - OffsetDateTime
- java.time - MonthDay
- java.time - LocalTime
- java.time - LocalDateTime
- java.time - LocalDate
- java.time - Instant
- java.time - Duration
- java.time - Clock
- java.time - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
java.time.Duration Class
Introduction
The java.time.Duration class models a quantity or amount of time in terms of seconds and nanoseconds. It can be accessed using other duration-based units, such as minutes and hours.
Class declaration
Following is the declaration for java.time.Duration class −
pubpc final class Duration extends Object implements TemporalAmount, Comparable<Duration>, Seriapzable
Field
Following are the fields for java.time.Duration class −
static Duration ZERO − Constant for a duration of zero.
Class methods
Sr.No. | Method & Description |
---|---|
1 | Returns a copy of this duration with a positive length. |
2 | Adds this duration to the specified temporal object. |
3 | Obtains a Duration representing the duration between two temporal objects. |
4 | Compares this duration to the specified Duration. |
5 | Returns a copy of this duration spanided by the specified value. |
6 | Checks if this duration is equal to the specified Duration. |
7 | Obtains an instance of Duration from a temporal amount. |
8 | Gets the value of the requested unit. |
9 | Gets the number of nanoseconds within the second in this duration. |
10 | Gets the number of seconds in this duration. |
11 | Gets the set of units supported by this duration. |
12 | A hash code for this duration. |
13 | Checks if this duration is negative, excluding zero. |
14 | Checks if this duration is zero length. |
15 | Returns a copy of this duration with the specified duration subtracted. |
16 | Returns a copy of this duration with the specified duration subtracted. |
17 | Returns a copy of this duration with the specified duration in standard 24 hour days subtracted. |
18 | Returns a copy of this duration with the specified duration in hours subtracted. |
19 | Returns a copy of this duration with the specified duration in milpseconds subtracted. |
20 | Returns a copy of this duration with the specified duration in minutes subtracted. |
21 | Returns a copy of this duration with the specified duration in nanoseconds subtracted. |
22 | Returns a copy of this duration with the specified duration in seconds subtracted. |
23 | Returns a copy of this duration multipped by the scalar. |
24 | Returns a copy of this duration with the length negated. |
25 | Obtains a Duration representing an amount in the specified unit. |
26 | Obtains a Duration representing a number of standard 24 hour days. |
27 | Obtains a Duration representing a number of standard hours. |
28 | Obtains a Duration representing a number of milpseconds. |
29 | Obtains a Duration representing a number of standard minutes. |
30 | Obtains a Duration representing a number of nanoseconds. |
31 | Obtains a Duration representing a number of seconds. |
32 | Obtains a Duration representing a number of seconds and an adjustment in nanoseconds. |
33 | Obtains a Duration from a text string such as PnDTnHnMn.nS. |
34 | Returns a copy of this duration with the specified duration added. |
35 | Returns a copy of this duration with the specified duration added. |
36 | Returns a copy of this duration with the specified duration in standard 24 hour days added. |
37 | Returns a copy of this duration with the specified duration in hours added. |
38 | Returns a copy of this duration with the specified duration in milpseconds added. |
39 | Returns a copy of this duration with the specified duration in minutes added. |
40 | Returns a copy of this duration with the specified duration in nanoseconds added. |
41 | Returns a copy of this duration with the specified duration in seconds added. |
42 | Subtracts this duration from the specified temporal object. |
43 | Gets the number of days in this duration. |
44 | Gets the number of hours in this duration. |
45 | Converts this duration to the total length in milpseconds. |
46 | Gets the number of minutes in this duration. |
47 | Converts this duration to the total length in nanoseconds expressed as a long. |
48 | A string representation of this duration using ISO-8601 seconds based representation, such as PT8H6M12.345S. |
49 | Returns a copy of this duration with the specified nano-of-second. |
50 | Returns a copy of this duration with the specified amount of seconds. |
Methods inherited
This class inherits methods from the following classes −
Java.lang.Object