Tuesday 3 July 2018

How to use get(int field) method of Java.util.calendar class | Java Date and Time


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

CalendarDemo.java

import java.util.Calendar;

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

        /*
         * public int get(int field)
         *
         * Parameters:
         *
         * field - the given calendar field.
         *
         * Returns:
         *
         * the value for the given calendar field.
         */

        System.out.println("Calendar's Year: " + cal.get(Calendar.YEAR));
        // Month - 0[Jan] to 11[Dec]
        System.out.println("Calendar's Month: " + cal.get(Calendar.MONTH));
        System.out.println("Calendar's Day: " + cal.get(Calendar.DAY_OF_MONTH));

    }

}

Output

Calendar's Year: 2018
Calendar's Month: 4
Calendar's Day: 16

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

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

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