Friday, 27 July 2018

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


Click here to watch on Youtube:
https://www.youtube.com/watch?v=5Y2zuQ5EiKc&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 time field.
         *
         * up - indicates if the value of the specified time field is
         * to be rolled up or rolled down. Use true if rolling up,
         * false otherwise.
         */

        cal.roll(Calendar.MONTH, true);

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

        cal.roll(Calendar.MONTH, false);

        System.out.println("After roll down, Month is " + cal.get(Calendar.MONTH));
    }
}

Output

Month is 8
After roll up, Month is 9
After roll down, Month is 8

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

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

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