Friday, 2 February 2018

How to use get method which accepts temporal field of MonthDay Class | Java 8 Date and Time


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

MonthDayDemo.java

import java.time.MonthDay;
import java.time.temporal.ChronoField;

public class MonthDayDemo
{

    public static void main(String[] args)
    {
        MonthDay monthDay = MonthDay.now();
        System.out.println(monthDay);

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


        int monthOfYear = monthDay.get(ChronoField.MONTH_OF_YEAR);
        System.out.println("monthOfYear = " + monthOfYear);

        int dayOfMonth = monthDay.get(ChronoField.DAY_OF_MONTH);
        System.out.println("dayOfMonth = " + dayOfMonth);

    }

}

Output

--01-19
monthOfYear = 1
dayOfMonth = 19

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/MonthDayDemo_get_field.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/MonthDayDemo_get_field

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/d57185a7bf9e23294d2a9e7b3cf655cc136de202/BasicJava/MonthDayDemo_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
  • No comments:

    Post a Comment