Monday, 26 March 2018

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


Click here to watch on Youtube: 
https://www.youtube.com/watch?v=IbmuE6d0G6U&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
         */


        long year = yearMonth.getLong(ChronoField.YEAR);
        System.out.println("year = " + year);

        long monthOfYear = yearMonth.getLong(ChronoField.MONTH_OF_YEAR);
        System.out.println("monthOfYear = " + monthOfYear);

    }

}

Output

yearMonth = 2018-03
year = 2018
monthOfYear = 3

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

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

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