created: 2022-07-17T15:56:00+08:00
updated: 2022-07-17T16:17:13+08:00
tags:
- DateTimeAPI
Standard Calendar
Standard Calendar
有两种表示时间的基本方式。一种人类时间,一种机器时间。Date-Time API 中的一些类旨在表示机器时间,而其他类更适合表示人类时间。
下表总结了 java.time 包中存储日期,时间信息的基于时间的类,或者可以用来测量时间量。
Class or Enum | Content | toString() Output | Where Discussed |
---|---|---|---|
Instant | Seconds (1) | 2013-08-20T15:16:26.355Z | Instant Class |
LocalDate | Year, Month, Day | 2013-08-20 | Date Classes |
LocalDateTime | Year, Month, Day, Hour, Minutes, Seconds | 2013-08-20T08:16:26.937 | Date and Time Classes |
ZonedDateTime | Year, Month, Day, Hour, Minutes, Seconds, Zone Offset, Zone ID | 2013-08-21T00:16:26.941+09:00[Asia/Tokyo] | Time Zone and Offset Classes |
LocalTime | Hour, Minutes, Seconds | 08:16:26.943 | Date and Time Classes |
MonthDay | Month, Day | --08-20 | Date Classes |
Year | Year | 2013 | Date Classes |
YearMonth | Year, Month | 2013-08 | Date Classes |
Month | Month | AUGUST | DayOfWeek and Month Enums |
OffsetDateTime | Year, Month, Day, Hour, Minutes, Seconds, Zone Offset | 2013-08-20T08:16:26.954-07:00 | Time Zone and Offset Classes |
OffsetTime | Hour, Minutes, Seconds, Zone Offset | 08:16:26.957-07:00 | Time Zone and Offset Classes |
Duration | Day (2), Hour (2), Minutes (2), Seconds | PT20H (20 hours) | Period and Duration |
Period | Year, Month, Day (3) | P10D (10 days) | Period and Duration |
Notes:
(1): Seconds are captured to nanosecond precision.
(2): This class does not store this information, but has methods to provide time in these units.
(3): When a Period is added to a
ZonedDateTime
, daylight saving time or other local time differences are observed.
[[枚举类DayOfWeek和Month]]