The date and time classes do not use time zone information. Time zone classes are discussed in the Working with the Time Zone and Offset Classes section. Date and time classes are summarized in Table 12 – Date and Time Class Summary. These classes are immutable and their names give a good idea of what they represent. In addition to these classes; there are several enumerations which work nicely with these classes. Table 12 – Date and Time Class Summary Class | Date | Time | Usage LocalDate | Yes | No | Represents a date. The primary fields are year, month, and day. Other fields can be accessed such as day-of-week and day-of-year. LocalTime | No | Yes | Represents time and typically viewed as a combination of an hour, minute and second. A nanosecond component is also supported. LocalDateTime | Yes | Yes | Represents a date and time. The class possesses methods to return individual parts of the date and time such as the day or hour. YearMonth | Yes | No | Supports only a month and a year field MonthDay | Yes | No | Supports only a month and a day Year | Yes | No | Supports only years
Date and time information is often locale specific. To address this concern, the Date and Time API transparently uses the Unicode Common Locale Data Repository (CLDR) (http://cldr.unicode.org/). This repository consists of data used to format information such as dates. It provides country specific information. In the next sections we will illustrate how the LocalDate, LocalTime, and LocalDateTime classes can be instantiated and used. Following this section we will examine the YearMonth, MonthDay, and Year classes. Databases often have specific types for date and time entities. The following shows how the new date and time classes map: – LocalDate is used with the SQL DATE type – LocalTime is used with the SQL TIME type – LocalDateTime is used with the SQL TIMESTAMP type.