java.time.OffsetDateTime 类
在本教程中,您将学习如何使用java.time.OffsetDateTime类,简介java.time.OffsetDateTime类表示与ISO-8601日历系统中的UTC/格林威治有偏移的日期时间,例如2007-12-03T10:15:30+01:00。
java.time.OffsetDateTime 类表示与 ISO-8601 日历系统中的 UTC/格林威治有偏移的日期时间,例如 2007-12-03T10:15:30+01:00。
类声明
Following is the declaration for java.time.OffsetDateTime class −
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 | 月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 和区域 ID 获取 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 weekToAdd)
返回此 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