Java Calendar.clear() method example

 Posted On  | Pooja Lakkihal 

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.

syntax

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());

        calendar.clear();

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

    }
}

output

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


© technicalkeeda.com 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0418 seconds.