介绍
- java.time.ZonedDateTime
- 类声明
@jdk.internal.ValueBased
public final class ZonedDateTime implements Temporal, ChronoZonedDateTime<LocalDate>, Serializable
- 带时区的日期时间
- 实现
Temporal
,支持的时间单位( TemporalUnit
)有
- NANOS
- MICROS
- MILLIS
- SECONDS
- MINUTES
- HOURS
- HALF_DAYS
- DAYS
- WEEKS
- MONTHS
- YEARS
- DECADES
- CENTURIES
- MILLENNIA
- ERAS
- 实现
TemporalAccessor
,支持的时间域( TemporalField
)有
- NANO_OF_SECOND
- NANO_OF_DAY
- MICRO_OF_SECOND
- MICRO_OF_DAY
- MILLI_OF_SECOND
- MILLI_OF_DAY
- SECOND_OF_MINUTE
- SECOND_OF_DAY
- MINUTE_OF_HOUR
- MINUTE_OF_DAY
- HOUR_OF_AMPM
- CLOCK_HOUR_OF_AMPM
- HOUR_OF_DAY
- CLOCK_HOUR_OF_DAY
- AMPM_OF_DAY
- DAY_OF_WEEK
- ALIGNED_DAY_OF_WEEK_IN_MONTH
- ALIGNED_DAY_OF_WEEK_IN_YEAR
- DAY_OF_MONTH
- DAY_OF_YEAR
- EPOCH_DAY
- ALIGNED_WEEK_OF_MONTH
- ALIGNED_WEEK_OF_YEAR
- MONTH_OF_YEAR
- PROLEPTIC_MONTH
- YEAR_OF_ERA
- YEAR
- ERA
- INSTANT_SECONDS
- OFFSET_SECONDS
- 内部存储是
private final LocalDateTime dateTime;
private final ZoneOffset offset;
private final ZoneId zone;
- 类似于
java.util.GregorianCalendar
,通过 toInstant
和 from
相互转换
API
static
- now
- of
- ofLocal
- ofInstant
- ofStrict
- from
- parse
- 反
toString
- 格式示例:
2007-12-03T10:15:30+01:00[Europe/Paris]
public
- truncatedTo
- toOffsetDateTime
- toString
get
- getYear
- getMonthValue
- getMonth
- getDayOfMonth
- getDayOfYear
- getDayOfWeek
- getHour
- getMinute
- getSecond
- getNano
with
- withYear
- withMonth
- withDayOfMonth
- withDayOfYear
- withHour
- withMinute
- withSecond
- withNano
- withFixedOffsetZone
plus/minus
- plusYears
- plusMonths
- plusWeeks
- plusDays
- plusHours
- plusMinutes
- plusSeconds
- plusNanos
- minusYears
- minusMonths
- minusWeeks
- minusDays
- minusHours
- minusMinutes
- minusSeconds
- minusNanos