手册
目录
收藏410
分享
阅读809
更新时间2025-07-22
前言:
在本教程中,您将学习如何使用java.time.ZonedDateTime 类
java.time.ZonedDateTime 类表示具有 ISO-8601 日历系统中时区的日期时间,例如 2007-12-03T10:15:30+01:00 Europe/Paris .
以下是 java.time.ZonedDateTime 类的声明 −
public final class ZonedDateTime
extends Object
implements Temporal, ChronoZonedDateTime, Serializable
点击 "运行实例" 按钮查看在线实例
| 序号 | 方法 & 描述 |
|---|---|
| 1 | boolean equals(Object obj)
检查此日期时间是否等于另一个日期时间。 |
| 2 | String format(DateTimeFormatter formatter)
使用指定的格式化程序格式化此日期时间。 |
| 3 | static ZonedDateTime from(TemporalAccessor temporal)
从时间对象获取 ZonedDateTime 的实例。 |
| 4 | int get(TemporalField field)
从此日期时间获取指定字段的值作为 int。 |
| 5 | int getDayOfMonth()
获取月份中的日期字段。 |
| 6 | DayOfWeek getDayOfWeek()
获取星期字段,它是一个枚举 DayOfWeek。 |
| 7 | int getDayOfYear()
获取一年中的日期字段。 |
| 8 | int getHour()
获取一天中的小时字段。 |
| 9 | long getLong(TemporalField field)
从此日期时间中获取指定字段的值作为 long。 |
| 10 | 月getMinute()
获取小时的分钟字段。 |
| 11 | Month getMonth()
使用 Month 枚举获取月份字段。 |
| 12 | int getMonthValue()
获取从 1 到 12 的月份字段。 |
| 13 | int getNano()
获取纳秒字段。 |
| 14 | ZoneOffset getOffset()
获取区域偏移量,例如'+01:00'。 |
| 15 | int getSecond()
获取秒字段。 |
| 16 | int getYear()
获取年份字段。 |
| 17 | ZoneId getZone()
获取时区,例如'Europe/Paris'。 |
| 18 | int hashCode()
此日期时间的哈希码。 |
| 19 | boolean isSupported(TemporalField field)
检查是否支持指定的字段。 |
| 20 | boolean isSupported(TemporalUnit unit)
检查是否支持指定的单位。 |
| 21 | ZonedDateTime minus(long amountToSubtract, TemporalUnit unit)
返回减去指定数量的此日期时间的副本。 |
| 22 | ZonedDateTime 减(TemporalAmount amountToSubtract)
返回此日期时间的副本,减去指定的数量。 |
| 23 | ZonedDateTime minusDays(long daysToSubtract)
返回此 ZonedDateTime 的副本,减去指定的天数。 |
| 24 | ZonedDateTime minusHours(long hoursToSubtract)
返回此 ZonedDateTime 的副本,减去指定的小时数。 |
| 25 | ZonedDateTime minusMinutes(long minutesToSubtract)
返回此 ZonedDateTime 的副本,减去指定的分钟数。 |
| 26 | ZonedDateTime minusMonths(long monthsToSubtract)
返回此 ZonedDateTime 的副本,减去指定的月数。 |
| 27 | ZonedDateTime minusNanos(long nanos)
返回此 ZonedDateTime 的副本,减去指定的纳秒数。 |
| 28 | ZonedDateTime minusSeconds(long seconds)
返回此 ZonedDateTime 的副本,减去指定的秒数。 |
| 29 | ZonedDateTime minusWeeks(long weeksToSubtract)
返回此 ZonedDateTime 的副本,减去指定的周数。 |
| 30 | ZonedDateTime minusYears(long yearsToSubtract)
返回此 ZonedDateTime 的副本,减去指定的年数。 |
| 31 | static ZonedDateTime now()
从默认时区的系统时钟获取当前日期时间。 |
| 32 | static ZonedDateTime now(Clock clock)
从指定时钟获取当前日期时间。 |
| 33 | static ZonedDateTime now(ZoneId zone)
从指定时区的系统时钟获取当前日期时间。 |
| 34 | static ZonedDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneId zone)
从年、月、日、小时、分钟、秒、纳秒和时区获取 ZonedDateTime 的实例。 |
| 35 | static ZonedDateTime of(LocalDate date, LocalTime time, ZoneId zone)
从日期和时间获取 ZonedDateTime 的实例。 |
| 36 | static ZonedDateTime of(LocalDateTime date, ZoneId zone)
从本地日期时间获取 ZonedDateTime 的实例。 |
| 37 | static ZonedDateTime ofInstant(Instant instant, ZoneId zone)
从 Instant 和区域 ID 获取 ZonedDateTime 的实例。 |
| 38 | static ZonedDateTime ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)
从结合本地日期时间和偏移量形成的瞬间获取 ZonedDateTime 的实例。 |
| 39 | static ZonedDateTime ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset)
如果可能,使用首选偏移量从本地日期时间获取 ZonedDateTime 的实例。 |
| 40 | static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)
获取 ZonedDateTime 的实例,严格验证本地日期时间、偏移量和区域 ID 的组合。 |
| 41 | static ZonedDateTime parse(CharSequence text)
从 2007-12-03T10:15:30+01:00[Europe/Paris] 等文本字符串中获取 ZonedDateTime 的实例。 |
| 42 | static ZonedDateTime parse(CharSequence text, DateTimeFormatter formatter)
使用特定格式化程序从文本字符串中获取 ZonedDateTime 的实例。 |
| 43 | ZonedDateTime plus(long amountToAdd, TemporalUnit unit)
返回此日期时间的副本,并添加指定的数量。 |
| 44 | ZonedDateTime plus(TemporalAmount amountToAdd)
返回此日期时间的副本,其中添加了指定的数量。 |
| 45 | ZonedDateTime plusDays(long daysToAdd)
返回此 ZonedDateTime 的副本,并添加指定的天数。 |
| 46 | ZonedDateTime plusHours(long hoursToAdd)
返回此 ZonedDateTime 的副本,并添加指定的小时数。 |
| 47 | ZonedDateTime plusMinutes(long minutesToAdd)
返回此 ZonedDateTime 的副本,并添加指定的分钟数。 |
| 48 | ZonedDateTime plusMonths(long monthsToAdd)
返回此 ZonedDateTime 的副本,并添加指定的月数。 |
| 49 | ZonedDateTime plusNanos(long nanos)
返回此 ZonedDateTime 的副本,并添加指定的纳秒数。 |
| 50 | ZonedDateTime plusSeconds(long seconds)
返回此 ZonedDateTime 的副本,并添加指定的秒数。 |
| 51 | ZonedDateTime plusWeeks(long weeksToAdd)
返回此 ZonedDateTime 的副本,并添加指定的周数。 |
| 52 | ZonedDateTime plusYears(long yearsToAdd)
返回此 ZonedDateTime 的副本,并添加指定的年数。 |
| 53 | 使用指定的查询查询此日期时间。 |
| 54 | ValueRange range(TemporalField field)
获取指定字段的有效值范围。 |
| 55 | LocalDate toLocalDate()
获取此日期时间的 LocalDate 部分。 |
| 56 | LocalTime toLocalTime()
获取此日期时间的 LocalTime 部分。 |
| 57 | OffsetDateTime toOffsetDateTime()
将此日期时间转换为 OffsetDateTime。 |
| 58 | String toString()
将此日期输出为字符串,例如 2007-12-03T10:15:30+01:00[Europe/Paris]。 |
| 59 | ZonedDateTime truncatedTo(TemporalUnit unit)
返回此 ZonedDateTime 的副本,其中时间被截断。 |
| 60 | long until(Temporal endExclusive, TemporalUnit unit)
以指定单位计算距离另一个日期时间的时间量。 |
| 61 | ZonedDateTime with(TemporalAdjuster adjuster)
返回此日期时间的调整副本。 |
| 62 | ZonedDateTime with(TemporalField field, long newValue)
返回此日期时间的副本,并将指定字段设置为新值。 |
| 63 | ZonedDateTime withDayOfMonth(int dayOfMonth)
返回此 ZonedDateTime 的副本,其中日期已更改。 |
| 64 | ZonedDateTime withDayOfYear(int dayOfYear)
返回此 ZonedDateTime 的副本,其中日期已更改。 |
| 65 | ZonedDateTime withEarlierOffsetAtOverlap()
返回此日期时间的副本,将区域偏移更改为本地时间线重叠处两个有效偏移中较早的一个。 |
| 66 | ZonedDateTime withFixedOffsetZone()
返回此日期时间的副本,其中区域 ID 设置为偏移量。 |
| 67 | ZonedDateTime withHour(int hour)
返回此 ZonedDateTime 的副本,其中更改了一天中的时间。 |
| 68 | ZonedDateTime withLaterOffsetAtOverlap()
返回此日期时间的副本,将区域偏移更改为本地时间线重叠处的两个有效偏移中的后者。 |
| 69 | ZonedDateTime withMinute(int minute)
返回此 ZonedDateTime 的副本,其中分钟已更改。 |
| 70 | ZonedDateTime withMonth(int month)
返回此 ZonedDateTime 的副本,其中更改了年份。 |
| 71 | ZonedDateTime withNano(int nanoOfSecond)
返回此 ZonedDateTime 的副本,更改了纳秒。 |
| 72 | ZonedDateTime withSecond(int second)
返回此 ZonedDateTime 的副本,其中秒数已更改。 |
| 73 | ZonedDateTime withYear(int year)
返回此 ZonedDateTime 的副本,其中年份已更改。 |
| 74 | ZonedDateTime withZoneSameInstant(ZoneId zone)
返回具有不同时区的此日期时间的副本,保留瞬间。 |
| 75 | ZonedDateTime withZoneSameLocal(ZoneId zone)
返回具有不同时区的此日期时间的副本,尽可能保留本地日期时间。 |
这个类继承了以下类的方法 −
相关
视频
RELATED VIDEOS
科技资讯
1
2
3
4
5
6
7
8
9
精选课程
共5课时
17.2万人学习
共49课时
77万人学习
共29课时
61.7万人学习
共25课时
39.3万人学习
共43课时
70.9万人学习
共25课时
61.6万人学习
共22课时
23万人学习
共28课时
33.9万人学习
共89课时
125万人学习