Friday 16 March 2018

How to use with method of Year Class which accepts temporalField and long | Java 8 Date and Time


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

YearDemo.java

import java.time.Year;
import java.time.temporal.ChronoField;

public class YearDemo
{

    public static void main(String[] args)
    {

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

        /*
         * Returns a copy of this year with the specified field set to
         * a new value.
         *
         * Parameters:
         *
         * field - the field to set in the result, not null
         *
         * newValue - the new value of the field in the result
         *
         * Returns:
         *
         * a Year based on this with the specified field set, not null
         */

        Year year2 = year1.with(ChronoField.YEAR, 2050);
        System.out.println("year2 = " + year2);

    }

}

Output

year1 = 2017
year2 = 2050

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

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

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