Thursday 7 June 2018

How to use minus(long months) and plus(long months) methods of Month Enum


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

MonthDemo1.java

import java.time.Month;

public class MonthDemo1
{
    public static void main(String[] args)
    {
        Month month = Month.of(2);
        System.out.println("Before minus, Month = "+month);
       
        /*
         * Parameters:
         *
         * months - the months to subtract, positive or negative
         *
         * Returns:
         *
         * the resulting month, not null
         */

        month = month.minus(1);
        System.out.println("After minus, Month  = "+month);
    }

}

Output

Before minus, Month = FEBRUARY
After minus, Month  = JANUARY

MonthDemo2.java

import java.time.Month;

public class MonthDemo2
{
    public static void main(String[] args)
    {
        Month month = Month.of(2);
        System.out.println("Before plus, Month = "+month);

        /*
         * Parameters:
         *
         * months - the months to add, positive or negative
         *
         * Returns:
         *
         * the resulting month, not null
         */

        month = month.plus(1);
        System.out.println("Before plus, Month = "+month);
    }

}

Output

Before plus, Month = FEBRUARY
Before plus, Month = MARCH

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/21e60817517fc375c595b23163eb96a6fc305b37/BasicJava_2018/MonthDemo_minus_plus/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Spring Tutorial
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a Comment