Friday, 27 July 2018

How to use roll(int field, int amount) method of Java.util.calendar class


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

CalendarDemo.java

import java.util.Calendar;

public class CalendarDemo
{
    public static void main(String[] args)
    {
        Calendar cal = Calendar.getInstance();
        cal.set(2017, 8, 24);
        System.out.println("Month is " + cal.get(Calendar.MONTH));

        /*
         * Parameters:
         *
         * field - the calendar field.
         *
         * amount - the signed amount to add to the calendar field.
         */

        cal.roll(Calendar.MONTH, 2);

        System.out.println(
                "After rolling 2, Month is " + cal.get(Calendar.MONTH));

        cal.roll(Calendar.MONTH, -4);

        System.out.println(
                "After rolling -4, Month is " + cal.get(Calendar.MONTH));
    }
}

Output

Month is 8
After rolling 2, Month is 10
After rolling -4, Month is 6

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

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

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