Java Calendar.clear() method example

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

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


public final void clear()

Java Calendar clear() example

  • Create CalendarApp instance which extends GregorianCalendar new CalendarApp();
  • calendar.getTime(); This will get the calendar time value.
  • calendar.clear(); It will set all the calendar field values.
  • 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 after clear is :- " + calendar.getTime());



The current date is :- Thu Jan 25 16:01:57 IST 2018
New Date after clear is :- Thu Jan 01 00:00:00 IST 1970