Java Date and time (10) Java.time.Instant__Java

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.