Tuesday, 27 March 2018

How to use at methods of YearMonth Class | Java 8 Date and Time


Click here to watch on Youtube:
https://www.youtube.com/watch?v=0lt-djOspcY&list=UUhwKlOVR041tngjerWxVccw

YearMonthDemo.java

import java.time.LocalDate;
import java.time.YearMonth;

public class YearMonthDemo
{

    public static void main(String[] args)
    {

        YearMonth yearMonth = YearMonth.of(2014, 11);
        System.out.println("yearMonth = " + yearMonth);

        /*
         * Parameters:
         *
         * dayOfMonth - the day-of-month to use, from 1 to 31
         *
         * Returns:
         *
         * the date formed from this year-month and the specified day,
         * not null
         */

        LocalDate localDate = yearMonth.atDay(2);
        System.out.println("localDate atDay(2) = " + localDate);

        /*
         * Returns:
         *
         * the last valid date of this year-month, not null
         */

        localDate = yearMonth.atEndOfMonth();
        System.out.println("localDate atEndOfMonth() = " + localDate);

    }

}

Output

yearMonth = 2014-11
localDate atDay(2) = 2014-11-02
localDate atEndOfMonth() = 2014-11-30

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

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

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