java.time.OffsetDateTime 類



介紹

java.time.OffsetDateTime 類表示具有相對於UTC/格林威治的偏移量的日期時間,使用 ISO-8601 日曆系統,例如 2007-12-03T10:15:30+01:00。

類宣告

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

public final class OffsetDateTime
   extends Object
      implements Temporal, TemporalAdjuster, Comparable<OffsetDateTime>, Serializable

欄位

以下是java.time.OffsetDateTime 類的欄位:

  • static OffsetDateTime MAX − 支援的最大 OffsetDateTime,'+999999999-12-31T23:59:59.999999999+18:00'。

  • static OffsetDateTime MIN − 支援的最小 OffsetDateTime,'-999999999-01-01T00:00:00-18:00'。

類方法

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

調整指定的時態物件,使其具有與該物件相同的日期和時間。

2 ZonedDateTime atZoneSameInstant(ZoneId zone)

將此日期時間與時區組合以建立 ZonedDateTime,確保結果具有相同的瞬間。

3 ZonedDateTime atZoneSimilarLocal(ZoneId zone)

將此日期時間與時區組合以建立 ZonedDateTime,嘗試保持相同的本地日期和時間。

4 int compareTo(OffsetDateTime other)

將此日期時間與另一個日期時間進行比較。

5 boolean equals(Object obj)

檢查此日期時間是否等於另一個日期時間。

6 String format(DateTimeFormatter formatter)

使用指定的格式化程式格式化此日期時間。

7 static OffsetDateTime from(TemporalAccessor temporal)

從時態物件獲取 OffsetDateTime 例項。

8 int get(TemporalField field)

將此日期時間中指定欄位的值作為 int 獲取。

9 int getDayOfMonth()

獲取月份中的天數字段。

10 DayOfWeek getDayOfWeek()

獲取星期幾欄位,這是一個 DayOfWeek 列舉。

11 int getDayOfYear()

獲取一年中的天數字段。

12 int getHour()

獲取一天中的小時數字段。

13 long getLong(TemporalField field)

將此日期時間中指定欄位的值作為 long 獲取。

14 int getMinute()

獲取小時中的分鐘數字段。

15 Month getMonth()

使用 Month 列舉獲取一年中的月份欄位。

16 int getMonthValue()

獲取一年中的月份欄位(從 1 到 12)。

17 int getNano()

獲取秒中的納秒數字段。

18 ZoneOffset getOffset()

獲取時區偏移量,例如 '+01:00'。

19 int getSecond()

獲取分鐘中的秒數字段。

20 int getYear()

獲取年份欄位。

21 int hashCode()

此日期時間的雜湊碼。

22 boolean isAfter(OffsetDateTime other)

檢查此日期時間是否在指定日期時間之後。

23 boolean isBefore(OffsetDateTime other)

檢查此日期時間是否在指定日期時間之前。

24 boolean isEqual(OffsetDateTime other)

檢查此日期時間是否等於指定的日期時間。

25 boolean isSupported(TemporalField field)

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

26 boolean isSupported(TemporalUnit unit)

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

27 OffsetDateTime minus(long amountToSubtract, TemporalUnit unit)

返回此日期時間的副本,其中減去了指定數量。

28 OffsetDateTime minus(TemporalAmount amountToSubtract)

返回此日期時間的副本,其中減去了指定數量。

29

OffsetDateTime minusDays(long daysToSubtract)

返回此 OffsetDateTime 的副本,其中減去了指定的天數。

30 OffsetDateTime minusHours(long hoursToSubtract)

返回此 OffsetDateTime 的副本,其中減去了指定的小時數。

31 OffsetDateTime minusMinutes(long minutesToSubtract)

返回此 OffsetDateTime 的副本,其中減去了指定的分鐘數。

32 OffsetDateTime minusMonths(long monthsToSubtract)

返回此 OffsetDateTime 的副本,其中減去了指定的月份數。

33 OffsetDateTime minusNanos(long nanos)

返回此 OffsetDateTime 的副本,其中減去了指定的納秒數。

34 OffsetDateTime minusSeconds(long seconds)

返回此 OffsetDateTime 的副本,其中減去了指定的秒數。

35 OffsetDateTime minusWeeks(long weeksToSubtract)

返回此 OffsetDateTime 的副本,其中減去了指定的週數。

36 OffsetDateTime minusYears(long yearsToSubtract)

返回此 OffsetDateTime 的副本,其中減去了指定的年份數。

37 static OffsetDateTime now()

從系統時鐘獲取預設時區中的當前日期時間。

38 static OffsetDateTime now(Clock clock)

從指定的時鐘獲取當前日期時間。

39 static OffsetDateTime now(ZoneId zone)

從系統時鐘獲取指定時區中的當前日期時間。

40 static OffsetDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset)

從年、月、日、小時、分鐘、秒、納秒和偏移量獲取 OffsetDateTime 例項。

41 static OffsetDateTime of(LocalDate date, LocalTime time, ZoneOffset offset)

從日期、時間和偏移量獲取 OffsetDateTime 例項。

42 static OffsetDateTime of(LocalDateTime dateTime, ZoneOffset offset)

從日期時間和偏移量獲取 OffsetDateTime 例項。

43 static OffsetDateTime ofInstant(Instant instant, ZoneId zone)

從 Instant 和 ZoneId 獲取 OffsetDateTime 例項。

44 static OffsetDateTime parse(CharSequence text)

從文字字串(例如 2007-12-03T10:15:30)獲取 OffsetDateTime 例項。

45 static OffsetDateTime parse(CharSequence text, DateTimeFormatter formatter)

使用指定的格式化程式從文字字串獲取 OffsetDateTime 例項。

46 OffsetDateTime plus(long amountToAdd, TemporalUnit unit)

返回此日期時間的副本,其中添加了指定數量。

47 OffsetDateTime plus(TemporalAmount amountToAdd)

返回此日期時間的副本,其中添加了指定數量。

48 OffsetDateTime plusDays(long daysToAdd)

返回此 OffsetDateTime 的副本,其中添加了指定的天數。

49 OffsetDateTime plusHours(long hoursToAdd)

返回此 OffsetDateTime 的副本,其中添加了指定的小時數。

50 OffsetDateTime plusMinutes(long minutesToAdd)

返回此 OffsetDateTime 的副本,其中添加了指定的分鐘數。

51 OffsetDateTime plusMonths(long monthsToAdd)

返回此 OffsetDateTime 的副本,其中添加了指定的月份數。

52 OffsetDateTime plusNanos(long nanos)

返回此 OffsetDateTime 的副本,其中添加了指定的納秒數。

53 OffsetDateTime plusSeconds(long seconds)

返回此 OffsetDateTime 的副本,其中添加了指定的秒數。

54 OffsetDateTime plusWeeks(long weeksToAdd)

返回此 OffsetDateTime 的副本,其中添加了指定的週數。

55 OffsetDateTime plusYears(long yearsToAdd)

返回此 OffsetDateTime 的副本,其中添加了指定的年份數。

56 <R> R query(TemporalQuery<R> query)

使用指定的查詢查詢此日期時間。

57 ValueRange range(TemporalField field)

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

58 static Comparator<OffsetDateTime> timeLineOrder()

獲取一個比較器,該比較器僅根據瞬間比較兩個 OffsetDateTime 例項。

59 long toEpochSecond()

將此日期時間轉換為自 1970-01-01T00:00:00Z 紀元以來的秒數。

60 Instant toInstant()

將此日期時間轉換為 Instant。

61 LocalDate toLocalDate()

獲取此日期時間的 LocalDate 部分。

62 LocalDateTime toLocalDateTime()

獲取此日期時間的 LocalDateTime 部分。

63 LocalTime toLocalTime()

獲取此日期時間的 LocalTime 部分。

64 OffsetTime toOffsetTime()

獲取此日期時間的 OffsetTime 部分。

65 String toString()

將此日期輸出為字串,例如 2007-12-03T10:15:30。

66 ZonedDateTime toZonedDateTime()

使用偏移量作為時區 ID 將此日期時間轉換為 ZonedDateTime。

67 OffsetDateTime truncatedTo(TemporalUnit unit)

返回此 OffsetDateTime 的副本,其中時間已截斷。

68 long until(Temporal endExclusive, TemporalUnit unit)

根據指定的單位計算到另一個日期時間的持續時間。

69 OffsetDateTime with(TemporalAdjuster adjuster)

返回此日期時間的調整後的副本。

70 OffsetDateTime with(TemporalField field, long newValue)

返回此日期時間的副本,其中指定欄位設定為新值。

71 OffsetDateTime withDayOfMonth(int dayOfMonth)

返回此 OffsetDateTime 的副本,其中更改了月份中的天數。

72 OffsetDateTime withDayOfYear(int dayOfYear)

返回此 OffsetDateTime 的副本,其中更改了一年中的天數。

73 OffsetDateTime withHour(int hour)

返回此 OffsetDateTime 的副本,其中更改了一天中的小時數。

74 OffsetDateTime withMinute(int minute)

返回此 OffsetDateTime 的副本,其中更改了小時中的分鐘數。

75 OffsetDateTime withMonth(int month)

返回此 OffsetDateTime 的副本,其中更改了一年中的月份。

76 OffsetDateTime withNano(int nanoOfSecond)

返回此 OffsetDateTime 的副本,其中更改了秒中的納秒數。

77 OffsetDateTime withOffsetSameInstant(ZoneOffset offset)

返回此 OffsetDateTime 的副本,其中指定了偏移量,確保結果位於同一瞬間。

78 OffsetDateTime withOffsetSameLocal(ZoneOffset offset)

返回此 OffsetDateTime 的副本,其中指定了偏移量,確保結果具有相同的本地日期時間。

79 OffsetDateTime withSecond(int second)

返回此 OffsetDateTime 的副本,其中修改了分鐘的秒數。

80 OffsetDateTime withYear(int year)

返回此 OffsetDateTime 的副本,其中修改了年份。

繼承的方法

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

  • Java.lang.Object
廣告