java.time.LocalDateTime 類



介紹

java.time.LocalDateTime 類表示 ISO-8601 日曆系統中不含時區的日期時間,例如 2007-12-03T10:15:30。

類宣告

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

public final class LocalDateTime
   extends Object
      implements Temporal, TemporalAdjuster, ChronoLocalDateTime, Serializable

欄位

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

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

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

類方法

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

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

2 OffsetDateTime atOffset(ZoneOffset offset)

將此日期時間與偏移時間組合以建立 OffsetDateTime。

3 ZonedDateTime atZone(ZoneId zone)

將此日期時間與時區組合以建立 ZonedDateTime。

4 int compareTo(ChronoLocalDateTime other)

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

5 boolean equals(Object obj)

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

6 String format(DateTimeFormatter formatter)

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

7 static LocalDateTime from(TemporalAccessor temporal)

從 Temporal 物件獲取 LocalDateTime 例項。

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()

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

17 int getNano()

獲取秒中的納秒欄位。

18 int getSecond()

獲取分鐘中的秒欄位。

19 int getYear()

獲取年份欄位。

20 int hashCode()

此日期時間的雜湊碼。

21 boolean isAfter(ChronoLocalDateTime other)

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

22 boolean isBefore(ChronoLocalDateTime other)

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

23 boolean isEqual(ChronoLocalDateTime other)

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

24 boolean isSupported(TemporalField field)

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

25 boolean isSupported(TemporalUnit unit)

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

26 LocalDateTime minus(long amountToSubtract, TemporalUnit unit)

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

27 LocalDateTime minus(TemporalAmount amountToSubtract)

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

28 LocalDateTime minusDays(long daysToSubtract)

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

29 LocalDateTime minusHours(long hoursToSubtract)

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

30 LocalDateTime minusMinutes(long minutesToSubtract)

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

31 LocalDateTime minusMonths(long monthsToSubtract)

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

32 LocalDateTime minusNanos(long nanos)

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

33 LocalDateTime minusSeconds(long seconds)

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

34 LocalDateTime minusWeeks(long weeksToSubtract)

返回此 LocalDateTime 的一個副本,其中減去了指定的星期數。

35 LocalDateTime minusYears(long yearsToSubtract)

返回此 LocalDateTime 的一個副本,其中減去了指定的年數。

36 static LocalDateTime now()

從系統時鐘獲取當前日期時間,以預設時區為準。

37 static LocalDateTime now(Clock clock)

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

38 static LocalDateTime now(ZoneId zone)

從系統時鐘獲取當前日期時間,以指定的時區為準。

39 static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute)

從年、月、日、時、分獲取 LocalDateTime 例項,並將秒和納秒設定為零。

40 static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second)

從年、月、日、時、分、秒獲取 LocalDateTime 例項,並將納秒設定為零。

41 static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond)

從年、月、日、時、分、秒和納秒獲取 LocalDateTime 例項。

42 static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute, int second)

從年、月、日、時、分、秒獲取 LocalDateTime 例項,並將納秒設定為零。

43 static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond)

從年、月、日、時、分、秒和納秒獲取 LocalDateTime 例項。

44 static LocalDateTime of(LocalDate date, LocalTime time)

從日期和時間獲取 LocalDateTime 例項。

45 static LocalDateTime ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset)

從 1970-01-01T00:00:00Z 的紀元獲取 LocalDateTime 例項。

46 static LocalDateTime ofInstant(Instant instant, ZoneId zone)

從 Instant 和時區 ID 獲取 LocalDateTime 例項。

47 static LocalDateTime parse(CharSequence text)

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

48 static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter)

使用特定格式化程式從文字字串獲取 LocalDateTime 例項。

49 LocalDateTime plus(long amountToAdd, TemporalUnit unit)

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

50 LocalDateTime plus(TemporalAmount amountToAdd)

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

51 LocalDateTime plusDays(long daysToAdd)

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

52 LocalDateTime plusHours(long hoursToAdd)

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

53 LocalDateTime plusMinutes(long minutesToAdd)

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

54 LocalDateTime plusMonths(long monthsToAdd)

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

55 LocalDateTime plusNanos(long nanos)

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

56 LocalDateTime plusSeconds(long seconds)

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

57 LocalDateTime plusWeeks(long weeksToAdd)

返回此 LocalDateTime 的一個副本,其中添加了指定的星期數。

58 LocalDateTime plusYears(long yearsToAdd)

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

59 <R> R query(TemporalQuery<R> query)

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

60 ValueRange range(TemporalField field)

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

61 LocalDate toLocalDate()

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

62 LocalTime toLocalTime()

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

63 String toString()

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

64 LocalDateTime truncatedTo(TemporalUnit unit)

返回此 LocalDateTime 的一個副本,其中時間被截斷。

65 long until(Temporal endExclusive, TemporalUnit unit)

計算以指定單位為準到另一個日期時間的時間量。

66 LocalDateTime with(TemporalAdjuster adjuster)

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

67 LocalDateTime with(TemporalField field, long newValue)

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

68 LocalDateTime withDayOfMonth(int dayOfMonth)

返回此 LocalDateTime 的一個副本,其中更改了月份中的第幾天。

69 LocalDateTime withDayOfYear(int dayOfYear)

返回此 LocalDateTime 的一個副本,其中更改了年中第幾天。

70 LocalDateTime withHour(int hour)

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

71 LocalDateTime withMinute(int minute)

返回此 LocalDateTime 的一個副本,其中更改了小時中的分鐘。

72 LocalDateTime withMonth(int month)

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

73 LocalDateTime withNano(int nanoOfSecond)

返回此 LocalDateTime 的一個副本,其中更改了秒中的納秒。

74 LocalDateTime withSecond(int second)

返回此 LocalDateTime 的一個副本,其中更改了分鐘中的秒。

75 LocalDateTime withYear(int year)

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

繼承的方法

此類繼承以下類的 method:

  • Java.lang.Object
廣告

© . All rights reserved.