Thursday, 5 April 2018

Java 8 Instant Class Introduction | Java 8 Date and Time | Java Date and Time


Click here to watch on Youtube:
https://www.youtube.com/watch?v=gm5O9vlrYIU&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge:
Java 8 Instant Class Introduction | Java 8 Date and Time | Java Date and Time
InstantDemo1.java

import java.time.Instant;

public class InstantDemo1
{
    public static void main(String[] args)
    {
        /*
         * Returns:the current instant using the system clock, not
         * null
         */

        Instant instant = Instant.now();
        System.out.println(instant);
    }

}

Output

2018-03-23T04:38:53.443Z

InstantDemo2.java

import java.time.Clock;
import java.time.Instant;

public class InstantDemo2
{
    public static void main(String[] args)
    {

        Clock clock = Clock.systemDefaultZone();
        System.out.println(clock);

        /*
         * Obtains the current instant from the specified clock.
         *
         * Parameters:
         *
         * clock - the clock to use, not null
         *
         * Returns:
         *
         * the current instant, not null
         */

        Instant instant = Instant.now(clock);
        System.out.println(instant);

    }

}

Output

SystemClock[Asia/Calcutta]
2018-03-23T04:34:48.679Z

Refer:
https://docs.oracle.com/javase/8/docs/api/index.html?java/time/Instant.html

Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/InstantDemo_intro.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/InstantDemo_intro

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/cd3c99ca353758a9764fe433bd563318d1244d3f/BasicJava_2018/InstantDemo_intro/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a Comment