Java Reference
In-Depth Information
Both the Duration and Period classes share many similar methods, and table 12.1 lists these.
Table 12.1. The common methods of date-time classes representing an
interval
Method
Static
Description
between
Yes
Creates an interval between two points in time
from
Yes
Creates an interval from a temporal unit
of
Yes
Creates an instance of this interval from its constituent parts
parse
Yes
Creates an instance of this interval from a String
addTo
No
Creates a copy of this interval adding to it the specified temporal object
get
No
Reads part of the state of this interval
isNegative
No
Checks if this interval is negative, excluding zero
isZero
No
Checks if this interval is zero length
minus
No
Creates a copy of this interval with an amount of time subtracted
multipliedBy
No
Creates a copy of this interval multiplied by the given scalar
negated
No
Creates a copy of this interval with the length negated
plus
No
Creates a copy of this interval with an amount of time added
subtractFrom
No
Subtracts this interval from the specified temporal object
All the classes we've investigated so far are immutable, and this is a great design choice to allow
a more functional programming style, ensure thread-safety, and preserve the consistency of the
domain model. Nevertheless, the new Date and Time API offers some handy methods to create a
modified version of those objects. For example, you may wish to add three days to an existing
LocalDate instance. We explore how to do this in the next section. In addition, we explore how
 
Search WWH ::




Custom Search