Java date and time
Original link
author : Jakob Jenkov
Translator : Ah for
Table of Contents : http://blog.csdn.net/tjgykhulj/article/details/68952451
(All translators ' comments will appear in this form, and strikethrough lines indicate a disputed or ambiguous place)
The instant class, in the Java Date and Time feature, represents an exact point on the timeline, defined as the time difference from the initial period (the initial time is GMT January 1, 1970 00:00)
It is measured 86,400 seconds a day and moves forward from the initial time.
Create a Instant instance
(Quote: You create an Instant instance using one of the Instant
Class factory methods. For instance, to create a Instant
Which represents this exact moment of
Instant. Now (), I can't translate the feeling of this sentence, so I enclose the original text here.
You can create a instant instance by instant the factory method of the class, for example, you can call Instant.now () to create an exact instant object that expresses the current time:
Instant now = Instant.now ();
There are other ways to create instant, please refer to the Java official documentation.
time to visit instant
There are two fields in a Instant object: the number of seconds from the initial time, the second nanosecond in the current second, and their combination expresses the current point in time. You can get their values in the following two ways:
Long seconds = Getepochsecond ()
int Nanos = Getnano ()
Calculation of Instant
The instant class has methods that you can use to get another instant value, such as:
Plusseconds ()
Plusmillis () Plusnanos () minusseconds ()
minusmillis
() Minusnanos ()
I'll show you two examples below to illustrate how these methods work:
Instant now = Instant.now ();
Instant later = Now.plusseconds (3);
Instant earlier = Now.minusseconds (3);
The first line gets a instant object that represents the current time. The second line creates a instant representation three seconds later, and the third row creates a instant representing three seconds ago.
Next Chapter: Java.time.Duration