Tuesday 10 April 2018

How to use isAfter, isBefore methods of Instant class | Java 8 Date and Time


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

InstantDemo.java

import java.time.Instant;

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

         Instant instant1 = Instant.parse("2016-12-03T10:15:30.00Z");
         System.out.println("instant1 = "+instant1);
       
         Instant instant2 = Instant.now();
         System.out.println("instant2 = "+instant2);
       
        /*
         * Parameters:
         *
         * otherInstant - the other instant to compare to, not null
         *
         * Returns:
         *
         * true if this instant is after the specified instant
         */

         System.out.println(instant1.isAfter(instant2));
       
        /*
         * Parameters:
         *
         * otherInstant - the other instant to compare to, not null
         *
         * Returns:
         *
         * true if this instant is before the specified instant
         */

         System.out.println(instant1.isBefore(instant2));

    }

}

Output

instant1 = 2016-12-03T10:15:30Z
instant2 = 2018-03-28T03:40:39.091Z
false
true

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

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

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