Java Reference
In-Depth Information
2014-12-27T05:36:42.199Z[GMT]
Yesterday: 2014-12-26T05:36:42.253Z
How It Works
The Date-Time API introduces a new class named Instant , which represents the
start of a nanosecond on the timeline in machine-based time. Being based on machine
time, the value for an Instant counts from the EPOCH (January 1, 1970 00:00:00Z).
Any values prior to the EPOCH are negative, and after the EPOCH the values are posit-
ive. The Instant class is perfect for obtaining a machine timestamp, as it includes all
pertinent date and time information to the nanosecond.
An Instant class is static and immutable, so to obtain the current timestamp, the
now() method can be called. Doing so returns a copy of the current Instant . The
Instant also includes conversion and calculation methods, each returning copies of
the Instant or other types. In the solution, the now() method returns the current
timestamp, and then a couple of examples follow, showing how to perform calculations
and obtain information on the Instant .
The Instant is an important new feature in JDK 8, as it makes it easy to work
with current time and date data. The other date and time classes, such as
LocalDateTime , are useful as well. However, the Instant is the most accurate
timestamp as it's based on nanosecond accuracy.
4-13. Converting Dates and Times Based
on the Time Zone
Problem
The application you are developing has the potential to be utilized throughout the
world. In some areas of the application, static dates and times need to be displayed,
rather than the system date and time. In such cases, those static dates and times need to
be converted to suit the particular time zone in which the application user is currently
residing.
Solution
Search WWH ::




Custom Search