Monday 21 May 2018

How to use until method of Instant class | Java 8 Date and Time


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

InstantDemo.java

import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

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

        Instant instant = Instant.parse("2017-12-03T10:15:30.00Z");
        System.out.println("instant = "+instant);
       
        ZonedDateTime zoneDateTime = ZonedDateTime.now();
        System.out.println("zoneDateTime = "+zoneDateTime);

        /*
         * Parameters:
         *
         * endExclusive - the end date, exclusive, which is converted
         * to an Instant, not null
         *
         * unit - the unit to measure the amount in, not null
         *
         * Returns:
         *
         * the amount of time between this instant and the end instant
         */


        long value = instant.until(zoneDateTime, ChronoUnit.DAYS);
        System.out.println(value);

    }

}

Output

instant = 2017-12-03T10:15:30Z
zoneDateTime = 2018-04-07T10:42:51.948+05:30[Asia/Calcutta]
124

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/80c7c27095bd0aa4eb0109eac12d92549dcd717d/BasicJava_2018/InstantDemo_until/?at=master

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

    Post a Comment