Monday, 26 March 2018

How to use get method of YearMonth Class which accepts TemporalField | Java 8 Date and Time


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

YearMonthDemo.java

import java.time.YearMonth;
import java.time.temporal.ChronoField;

public class YearMonthDemo
{

    public static void main(String[] args)
    {
        YearMonth yearMonth = YearMonth.now();
        System.out.println("yearMonth = " + yearMonth);

        /*
         * Parameters:
         *
         * field - the field to get, not null
         *
         * Returns:
         *
         * the value for the field
         */

        int year = yearMonth.get(ChronoField.YEAR);
        System.out.println("year = " + year);

        /*
         * Parameters:
         *
         * field - the field to get, not null
         *
         * Returns:
         *
         * the value for the field
         */

        int monthValue = yearMonth.get(ChronoField.MONTH_OF_YEAR);
        System.out.println("monthValue = " + monthValue);
    }

}

Output

yearMonth = 2018-03
year = 2018
monthValue = 3

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

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

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