java.time.OffsetDateTime類

java.time.OffsetDateTime類表示ISO-8601日曆系統中與UTC/Greenwich的偏移量的日期時間,例如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

Month getMinute()

獲取分鐘字段。

15

Month getMonth()

使用Month枚舉獲取月份字段。

16

int getMonthValue()

獲取112之間的月份字段。

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和區域ID獲取OffsetDateTime的實例。

44

static OffsetDateTime parse(CharSequence text)

從文本字符串中獲取OffsetDateTime的實例,例如:2007-12-03T10:15:30

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 plusWeeks(long weeksToAdd)

返回此OffsetDateTime的副本,並添加指定的週數。

54

OffsetDateTime plusWeeks(long weeksToAdd)

返回此OffsetDateTime的副本,並添加指定的週數。

55

OffsetDateTime plusYears(long yearsToAdd)

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

56

R query(TemporalQuery query)

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

57

ValueRange range(TemporalField field)

獲取指定字段的有效值範圍。

58

static Comparator timeLineOrder()

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

59

long toEpochSecond()

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

60

Instant toInstant()

將此日期時間轉換爲即時。

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