Thursday 4 October 2018

How to use constructors of Java.util.GregorianCalendar class | Java Date and Time


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

GregorianCalendarDemo.java

import java.util.GregorianCalendar;

public class GregorianCalendarDemo
{
    public static void main(String[] args)
    {
        /*
         * Parameters:
         *
         * year - the value used to set the YEAR calendar field in the
         * calendar.
         *
         * month - the value used to set the MONTH calendar field in
         * the calendar. Month value is 0-based. e.g., 0 for January.
         *
         * dayOfMonth - the value used to set the DAY_OF_MONTH
         * calendar field in the calendar.
         */

        GregorianCalendar cal1 = new GregorianCalendar(2017, 10, 21);
        System.out.println(cal1.getTime());
       
       
        /*
         * Parameters:
         *
         * year - the value used to set the YEAR calendar field in the
         * calendar.
         *
         * month - the value used to set the MONTH calendar field in
         * the calendar. Month value is 0-based. e.g., 0 for January.
         *
         * dayOfMonth - the value used to set the DAY_OF_MONTH
         * calendar field in the calendar.
         *
         * hourOfDay - the value used to set the HOUR_OF_DAY calendar
         * field in the calendar.
         *
         * minute - the value used to set the MINUTE calendar field in
         * the calendar.
         */

        GregorianCalendar cal2 = new GregorianCalendar(2017, 2, 9, 22, 23);
        System.out.println(cal2.getTime());
       
        /*
         * Parameters:
         *
         * year - the value used to set the YEAR calendar field in the
         * calendar.
         *
         * month - the value used to set the MONTH calendar field in
         * the calendar. Month value is 0-based. e.g., 0 for January.
         *
         * dayOfMonth - the value used to set the DAY_OF_MONTH
         * calendar field in the calendar.
         *
         * hourOfDay - the value used to set the HOUR_OF_DAY calendar
         * field in the calendar.
         *
         * minute - the value used to set the MINUTE calendar field in
         * the calendar.
         *
         * second - the value used to set the SECOND calendar field in
         * the calendar.
         */

        GregorianCalendar cal3 = new GregorianCalendar(2017,2,9,40,43,52);
        System.out.println(cal3.getTime());
    }
}

Output

Tue Nov 21 00:00:00 IST 2017
Thu Mar 09 22:23:00 IST 2017
Fri Mar 10 16:43:52 IST 2017

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

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

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