Documentation

The Java™ Tutorials
Hide TOC
Standard Calendar标准日历
Trail: Date Time

Lesson: Standard Calendar课程:标准日历

The core of the Date-Time API is the java.time package. 日期时间API的核心是java.time包。The classes defined in java.time base their calendar system on the ISO calendar, which is the world standard for representing date and time. java.time中定义的类将其日历系统基于ISO日历,ISO日历是表示日期和时间的世界标准。The ISO calendar follows the proleptic Gregorian rules. ISO日历遵循前公历规则。The Gregorian calendar was introduced in 1582; in the proleptic Gregorian calendar, dates are extended backwards from that time to create a consistent, unified timeline and to simplify date calculations.1582年引入了公历;在前公历中,日期从该时间向后延伸,以创建一致、一致性的时间线,并简化日期计算。

This lesson covers the following topics:本课程涵盖以下主题:

Overview概述

This section compares the concepts of human time and machine time provides a table of the primary temporal-based classes in the java.time package.本节比较了人工时间和机器时间的概念,并提供了java.time包中主要基于时态的类的表。

DayOfWeek and Month EnumsDayOfWeek枚举和Month枚举

This section discusses the enum that defines the days of the week (DayOfWeek) and the enum that defines months (Month).本节讨论定义星期几(DayOfWeek)的枚举和定义月份(Month)的枚举。

Date Classes日期类

This section shows the temporal-based classes that deal only with dates, without time or time zones. 本节展示了基于时态的类,这些类只处理日期,不处理时间或时区。The four classes are LocalDate, YearMonth, MonthDay and Year.这四个类是LocalDateYearMonthMonthDayYear

Date and Time Classes日期和时间类

This section presents the LocalTime and LocalDateTime classes, which deal with time, and date and time, respectively, but without time zones.本节介绍LocalTime类和LocalDateTime类,它们分别处理时间、日期和时间,但没有时区。

Time Zone and Offset Classes时区类和时区偏移类

This section discusses the temporal-based classes that store time zone (or time zone offset) information, ZonedDateTime, OffsetDateTime, and OffsetTime. 本节讨论存储时区(或时区偏移)信息的、基于时态的ZonedDateTimeOffsetDateTimeOffsetTime类。The supporting classes, ZoneId, ZoneRules, and ZoneOffset, are also discussed.还讨论了支持类ZoneIdZoneRulesZoneOffset

Instant Class瞬间类

This section discusses the Instant class, which represents an instantaneous moment on the timeline.本节讨论Instant类,它表示时间线上的一个瞬间。

Parsing and Formatting解析和格式化

This section provides an overview of how to use the predefined formatters to format and parse date and time values.本节概述如何使用预定义的格式化程序格式化和解析日期和时间值。

The Temporal Package临时包

This section presents an overview of the java.time.temporal package, which supports the temporal classes, fields (TemporalField and ChronoField) and units (TemporalUnit and ChronoUnit). 本节概述java.time.temporal包,该包支持时态类、字段(TemporalFieldChronoField)和单元(TemporalUnitChronoUnit)。This section also explains how to use a temporal adjuster to retrieve an adjusted time value, such as "the first Tuesday after April 11", and how to perform a temporal query.本节还解释了如何使用时间调整器检索调整后的时间值,例如“4月11日后的第一个星期二”,以及如何执行时间查询。

Period and Duration期间和持续时间

This section explains how to calculate an amount of time, using both the Period and Duration classes, as well as the ChronoUnit.between method.本节介绍如何使用PeriodDuration类以及ChronoUnit.between方法计算时间量。

Clock时钟

This section provides a brief overview of the Clock class. 本节简要概述Clock类。You can use this class to provide an alternative clock to the system clock.可以使用此类为系统时钟提供替代时钟。

Non-ISO Date Conversion非ISO日期转换

This section explains how to convert from a date in the ISO calendar system to a date in a non-ISO calendar system, such as a JapaneseDate or a ThaiBuddhistDate.本节介绍如何将ISO日历系统中的日期转换为非ISO日历系统中的日期,如JapaneseDateThaiBuddhistDate

Legacy Date-Time Code遗留日期时间代码

This section offers some tips on how to convert older java.util.Date and java.util.Calendar code to the Date-Time API.本节提供了一些关于如何将旧的java.util.Datejava.util.Calendar代码转换为日期时间API的技巧。

Summary小结

This section provides a summary of the Standard Calendar lesson.本节提供标准日历课程的摘要。


Previous page: Previous Lesson
Next page: Overview