Tuesday 6 February 2018

How to set month and day using with methods of MonthDay Class


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

MonthDayDemo.java

import java.time.Month;
import java.time.MonthDay;

public class MonthDayDemo
{

    public static void main(String[] args)
    {
        MonthDay monthDay = MonthDay.parse("--12-15");

        System.out.println("Before month Change = " + monthDay);

        /*
         * Parameters:
         *
         * month - the month-of-year to set in the returned month-day,
         * not null
         *
         * Returns:a MonthDay based on this month-day with the
         * requested month, not null
         */

        monthDay = monthDay.with(Month.APRIL);

        System.out.println("After month Change1 = " + monthDay);

        /*
         * Parameters:
         *
         * month - the month-of-year to set in the returned month-day,
         * from 1 (January) to 12 (December)
         *
         * Returns: a MonthDay based on this month-day with the
         * requested month, not null
         *
         */

        monthDay = monthDay.withMonth(8);

        System.out.println("After month Change2 = " + monthDay);

        /*
         * Parameters:
         *
         * dayOfMonth - the day-of-month to set in the return
         * month-day, from 1 to 31
         *
         * Returns:a MonthDay based on this month-day with the
         * requested day, not null
         */


        monthDay = monthDay.withDayOfMonth(30);

        System.out.println("After day Change    = " + monthDay);
    }

}

Output

Before month Change = --12-15
After month Change1 = --04-15
After month Change2 = --08-15
After day Change    = --08-30

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/1e56a5b0ee03d5726eaa59561253516c29bd898c/BasicJava/MonthDayDemo_with/?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