java.time.Instant 類



介紹

java.time.Instant 類模擬時間線上的單個瞬時點。

類宣告

以下是 java.time.Instant 類的宣告:

public final class Instant
   extends Object
      implements Temporal, TemporalAdjuster, Comparable, Serializable

欄位

  • 以下是 Java.time.Instant 類的欄位:

  • static Instant EPOCH - 1970-01-01T00:00:00Z紀元時刻的常量。

  • static Instant MAX - 支援的最大 Instant,'1000000000-12-31T23:59:59.999999999Z'。

  • static Instant MIN - 支援的最小 Instant,'-1000000000-01-01T00:00Z'。

類方法

序號 方法及描述
1 Temporal adjustInto(Temporal temporal)

調整指定的 Temporal 物件以具有此 Instant。

2 OffsetDateTime atOffset(ZoneOffset offset)

將此 Instant 與偏移量組合以建立 OffsetDateTime。

3 ZonedDateTime atZone(ZoneId zone)

將此 Instant 與時區組合以建立 ZonedDateTime。

4 int compareTo(Instant otherInstant)

將此 Instant 與指定的 Instant 進行比較。

5 boolean equals(Object otherInstant)

檢查此 Instant 是否等於指定的 Instant。

6 static Instant from(TemporalAccessor temporal)

從 Temporal 物件獲取 Instant 例項。

7 int get(TemporalField field)

獲取此 Instant 中指定欄位的值,作為 int。

8 long getEpochSecond()

獲取自 1970-01-01T00:00:00Z 的 Java 紀元以來的秒數。

9 long getLong(TemporalField field)

獲取此 Instant 中指定欄位的值,作為 long。

10 int getNano()

獲取自秒開始以來的納秒數,沿著時間線向後。

11 int hashCode()

返回此 Instant 的雜湊碼。

12 boolean isAfter(Instant otherInstant)

檢查此 Instant 是否在指定的 Instant 之後。

13 boolean isBefore(Instant otherInstant)

檢查此 Instant 是否在指定的 Instant 之前。

14 boolean isSupported(TemporalField field)

檢查是否支援指定的欄位。

15 boolean isSupported(TemporalUnit unit)

檢查是否支援指定的單位。

16 Instant minus(long amountToSubtract, TemporalUnit unit)

返回此 Instant 的副本,減去指定數量。

17 Instant minus(TemporalAmount amountToSubtract)

返回此 Instant 的副本,減去指定數量。

18 Instant minusMillis(long millisToSubtract)

返回此 Instant 的副本,減去指定的毫秒持續時間。

19 Instant minusNanos(long nanosToSubtract)

返回此 Instant 的副本,減去指定的納秒持續時間。

20 Instant minusSeconds(long secondsToSubtract)

返回此 Instant 的副本,減去指定的秒持續時間。

21 static Instant now()

從系統時鐘獲取當前 Instant。

22 static Instant now(Clock clock)

從指定的時鐘獲取當前 Instant。

23 static Instant ofEpochMilli(long epochMilli)

使用自 1970-01-01T00:00:00Z 紀元以來的毫秒數獲取 Instant 例項。

24 static Instant ofEpochSecond(long epochSecond)

使用自 1970-01-01T00:00:00Z 紀元以來的秒數獲取 Instant 例項。

25 static Instant ofEpochSecond(long epochSecond, long nanoAdjustment)

使用自 1970-01-01T00:00:00Z 紀元以來的秒數和納秒秒分數獲取 Instant 例項。

26 static Instant parse(CharSequence text)

從文字字串(例如 2007-12-03T10:15:30.00Z)獲取 Instant 例項。

27 Instant plus(long amountToAdd, TemporalUnit unit)

返回此 Instant 的副本,加上指定數量。

28 Instant plus(TemporalAmount amountToAdd)

返回此 Instant 的副本,加上指定數量。

29 Instant plusMillis(long millisToAdd)

返回此 Instant 的副本,加上指定的毫秒持續時間。

30 Instant plusNanos(long nanosToAdd)

返回此 Instant 的副本,加上指定的納秒持續時間。

31 Instant plusSeconds(long secondsToAdd)

返回此 Instant 的副本,加上指定的秒持續時間。

32 R query(TemporalQueryquery)

使用指定的查詢查詢此 Instant。

33 ValueRange range(TemporalField field)

獲取指定欄位的有效值範圍。

34 long toEpochMilli()

將此 Instant 轉換為自 1970-01-01T00:00:00Z 紀元以來的毫秒數。

35 String toString()

使用 ISO-8601 表示法表示此 Instant 的字串。

36 Instant truncatedTo(TemporalUnit unit)

返回此 Instant 的副本,截斷到指定的單位。

37 long until(Temporal endExclusive, TemporalUnit unit)

計算以指定單位表示的另一個 Instant 之前的時間量。

38 Instant with(TemporalAdjuster adjuster)

返回此 Instant 的調整副本。

39 Instant with(TemporalField field, long newValue)

返回此 Instant 的副本,其中指定的欄位設定為新值。

繼承的方法

此類繼承自以下類的方法:

  • Java.lang.Object
廣告