Java Calendar.clear(int field) method example

In this java tutorial, You will learn how to set the calendar field values and the time value.

Sets the given calendar field value and the time value (millisecond offset from the Epoch) of this Calendar undefined.


public final void clear(int field)


field - the calendar field to be cleared.

Java Calendar clear(int field) example

  • Create CalendarApp instance which extends GregorianCalendar new CalendarApp();
  • calendar.getTime(); This will get the calendar time value.
  • calendar.clear(calendar.YEAR); It will clear the calendar field value.
  • calendar.set(GregorianCalendar.YEAR, 1993); It will calendar date to new value.
  • calendar.computeTime(); It will compute time according to the new date.
  • Print the new date by calendar.getTime()
package com.technicalkeeda;

import java.util.GregorianCalendar;

public class CalenderApp extends GregorianCalendar {

    public static void main(String[] args) {

        CalenderApp calendar = new CalenderApp();
        System.out.println("The current date is :- " + calendar.getTime());


        System.out.println("New Date is :- " + calendar.getTime());



The current date is :- Thu Jan 25 15:59:01 IST 2018
New Date is :- Sun Jan 25 15:59:01 IST 1970