Thursday, 5 April 2018

How to create an Instant object using MAX, MIN and EPOCH constants | Java 8 Date and Time


Click here to watch on Youtube: 
https://www.youtube.com/watch?v=Rs-9frFQHrA&list=UUhwKlOVR041tngjerWxVccw

InstantDemo.java

import java.time.Instant;

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

        /*
         * Instant MAX defines the maximum supported Instant,
         * '1000000000-12-31T23:59:59.999999999Z' is the value.
         */

        Instant instant = Instant.MAX;
        System.out.println("Max = "+instant);
        System.out.println("Max EpochSecond = "+instant.getEpochSecond());
       
        /*
         * Instant MIN defines the minimum supported Instant,
         * '-1000000000-01-01T00:00Z'.
         */

        instant = Instant.MIN;
        System.out.println("Min = "+instant);
        System.out.println("Min EpochSecond = "+instant.getEpochSecond());
       
        /*
         * Instant EPOCH defines the constant for the
         * 1970-01-01T00:00:00Z epoch instant.
         */

        instant = Instant.EPOCH;
        System.out.println("EPOCH = "+instant);
        System.out.println("EPOCH EpochSecond = "+instant.getEpochSecond());
       
    }

}

Output

Max = +1000000000-12-31T23:59:59.999999999Z
Max EpochSecond = 31556889864403199
Min = -1000000000-01-01T00:00:00Z
Min EpochSecond = -31557014167219200
EPOCH = 1970-01-01T00:00:00Z
EPOCH EpochSecond = 0

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/cd3c99ca353758a9764fe433bd563318d1244d3f/BasicJava_2018/InstantDemo_max_min/?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