Sunday 15 July 2018

How to use set methods of Java.util.calendar class


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

CalendarDemo1.java

import java.util.Calendar;

public class CalendarDemo1
{
    public static void main(String[] args)
    {
        Calendar cal = Calendar.getInstance();

        System.out.println("Before set = " + cal.getTime());

        /*
         * Parameters:
         *
         * year - the value used to set the YEAR calendar field.
         *
         * month - the value used to set the MONTH calendar field.
         * Month value is 0-based. e.g., 0 for January.
         *
         * date - the value used to set the DAY_OF_MONTH calendar
         * field.
         */

        cal.set(2000, 11, 14);

        // print the result
        System.out.println("After set  = " + cal.getTime());
    }
}

Output

Before set = Tue Jun 26 09:42:15 IST 2018
After set  = Thu Dec 14 09:42:15 IST 2000

CalendarDemo2.java

import java.util.Calendar;

public class CalendarDemo2
{
    public static void main(String[] args)
    {
        Calendar cal = Calendar.getInstance();

        System.out.println("Before set = " + cal.getTime());

        /*
         * Parameters:
         *
         * year - the value used to set the YEAR calendar field.
         *
         * month - the value used to set the MONTH calendar field.
         * Month value is 0-based. e.g., 0 for January.
         *
         * date - the value used to set the DAY_OF_MONTH calendar
         * field.
         *
         * hourOfDay - the value used to set the HOUR_OF_DAY calendar
         * field.
         *
         * minute - the value used to set the MINUTE calendar field.
         */

        cal.set(2000, 11, 14, 2, 30);

        // print the result
        System.out.println("After set  = " + cal.getTime());
    }

}

Output

Before set = Tue Jun 26 09:42:22 IST 2018
After set  = Thu Dec 14 02:30:22 IST 2000

CalendarDemo3.java

import java.util.Calendar;

public class CalendarDemo3
{
    public static void main(String[] args)
    {
        Calendar cal = Calendar.getInstance();

        System.out.println("Before set = " + cal.getTime());

        /*
         * Parameters:
         *
         * year - the value used to set the YEAR calendar field.
         *
         * month - the value used to set the MONTH calendar field.
         * Month value is 0-based. e.g., 0 for January.
         *
         * date - the value used to set the DAY_OF_MONTH calendar
         * field.
         *
         * hourOfDay - the value used to set the HOUR_OF_DAY calendar
         * field.
         *
         * minute - the value used to set the MINUTE calendar field.
         *
         * second - the value used to set the SECOND calendar field.
         */

        cal.set(2000, 11, 15, 2, 30, 10);

        // print the result
        System.out.println("After set  = " + cal.getTime());
    }

}

Output

Before set = Tue Jun 26 09:42:33 IST 2018
After set  = Fri Dec 15 02:30:10 IST 2000

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

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

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