← 返回首页
TemporalAmount (Java SE 26 & JDK 26)
JavaScript is disabled on your browser.
Contents  
  1. Description
  2. Method Summary
  3. Method Details
    1. get(TemporalUnit)
    2. getUnits()
    3. addTo(Temporal)
    4. subtractFrom(Temporal)
Hide sidebar  Show sidebar

Interface TemporalAmount

All Known Subinterfaces: ChronoPeriod All Known Implementing Classes: Duration, Period
public interface TemporalAmount
Framework-level interface defining an amount of time, such as "6 hours", "8 days" or "2 years and 3 months".

This is the base interface type for amounts of time. An amount is distinct from a date or time-of-day in that it is not tied to any specific point on the time-line.

The amount can be thought of as a Map of TemporalUnit to long, exposed via getUnits() and get(TemporalUnit). A simple case might have a single unit-value pair, such as "6 hours". A more complex case may have multiple unit-value pairs, such as "7 years, 3 months and 5 days".

There are two common implementations. Period is a date-based implementation, storing years, months and days. Duration is a time-based implementation, storing seconds and nanoseconds, but providing some access using other duration based units such as minutes, hours and fixed 24-hour days.

This interface is a framework-level interface that should not be widely used in application code. Instead, applications should create and pass around instances of concrete types, such as Period and Duration.

Implementation Requirements: This interface places no restrictions on the mutability of implementations, however immutability is strongly recommended. Since: 1.8

Scripting on this page tracks web page traffic, but does not change the content in any way.