Tuesday 24 July 2018

How to use clear(int field) method of Java.util.calendar class


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

CalendarDemo.java

import java.util.Calendar;

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

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

        /*
         * Parameters:
         *
         * field - the calendar field to be cleared.
         */

        cal.clear(Calendar.YEAR);

        System.out.println("After clear  = " + cal.getTime());
    }
}

Output

Before clear = Sun Jul 01 10:50:38 IST 2018
After clear  = Wed Jul 01 10:50:38 IST 1970

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

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

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