Java Reference
In-Depth Information
// Construct a birth date and time from date-time components
LocalDate myBirthDate = LocalDate.of(1968, JANUARY, 12);
LocalTime myBirthTime = LocalTime.of(7, 30);
System.out.println("My Birth Date: " + myBirthDate);
System.out.println("My Birth Time: " + myBirthTime);
}
}
Current Date: 2014-01-02
Current Time: 13:36:43.474
Current Date and Time: 2014-01-02T13:36:43.474
Current Date, Time, and Zone: 2014-01-02T13:36:43.474-06:00[America/Chicago]
My Birth Date: 1968-01-12
My Birth Time: 07:30
The program uses four classes to get a local date, a time, a datetime, and a datetime with a time zone. In the
legacy Date-Time API, you could have gotten a similar result using only the Calendar class.
The Date-Time API is pretty comprehensive. It spans about 80 classes and about 1,000 methods. It lets you
represent and manipulate dates and times using different scales and different calendar systems. Several local
standards and one universal standard (ISO-8601) have been in use for timekeeping. To take full advantage of the
Date-Time API, you need to understand the history of timekeeping. The next few sections will give you a brief
overview of different ways to measure time using calendar systems and ISO-8601 date and time standards. If you
have a good understanding of these topics, you may skip these sections and continue from the “Exploring the New
Date-Time API” section.
Evolution of Timekeeping
A scale is used to measure the quantity of physical things such as length of a string in meters, weight of a person in
pounds, volume of water in liters, etc. Here, meters, pounds, and liters are units of measurement on a particular scale.
How do we measure time? Time is not a physical thing. To measure time, we link it to a periodic physical
phenomenon, for example, swinging of a pendulum, rotation of earth on its axis, revolution of earth around the sun,
oscillations of an electromagnetic signal associated with a quantum transition between two energy levels in an atom,
etc. Thus, a time scale is an arrangement of events to define the duration of time.
In ancient times, events such as sunrise and sunset, which are generated because of the rotation of Earth on its
axis, were used as a time scale; the unit of the time scale was day. Duration between two consecutive sunrises counted
as one day.
As the human civilization progressed, devices for timekeeping were developed. Some of those were
A sundial based on the position of the sun
A mechanical clock based on periodic movement of a pendulum
Finally, an atomic clock based on the properties of the caesium-133 atom
A clock is a timekeeping device that consists of two components: a frequency standard and a counter. The
frequency standard in a clock is a component to obtain equally spaced periodic events to measure the length of a
desired time interval. The counter (also called an accumulator or adder) counts the number of occurrences of the
periodic event. For example, in a pendulum clock, the occurrence of a complete cycle of a pendulum indicates a time
interval of one second, gears count the number of seconds, and the face of the clock displays the time. Even in ancient
 
Search WWH ::




Custom Search