Friday 16 March 2018

How to use until method of Year Class | Java 8 Date and Time


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

YearDemo.java

import java.time.Year;
import java.time.temporal.ChronoUnit;

public class YearDemo
{

    public static void main(String[] args)
    {

        Year year1 = Year.of(2017);
        System.out.println("year1 = " + year1);
        Year year2 = Year.of(2030);
        System.out.println("year2 = " + year2);

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

        long value = year1.until(year2, ChronoUnit.YEARS);
        System.out.println(value);

    }

}

Output

year1 = 2017
year2 = 2030
13

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

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

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