Java GregorianCalendar setGregorianChange() Method



Description

The Java GregorianCalendar setGregorianChange(Date date) method sets the GregorianCalendar change date. This is the point when the switch from Julian dates to Gregorian dates occurred. Default is October 15, 1582 (Gregorian). Previous to this, dates will be in the Julian calendar.

Declaration

Following is the declaration for java.util.GregorianCalendar.setGregorianChange() method

public void setGregorianChange(Date date)

Parameters

date − the given Gregorian cutover date.

Return Value

This method does not return a value.

Exception

NA

Example

The following example shows the usage of Java GregorianCalendar setGregorianChange() method. We're creating a GregorianCalendar instance of current date. We've modified calendar usign setGregorianChange() method and then printed the same.

package com.tutorialspoint;

import java.util.Date;
import java.util.GregorianCalendar;

public class GregorianCalendarDemo {
   public static void main(String[] args) {

      // create a new calendar
      GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();

      // print the current date and time
      System.out.println("" + cal.getTime());

      // set gregorian change at another date
      cal.setGregorianChange(new Date(92, 12, 10));
      System.out.println("Gregorian Change Date" + cal.getGregorianChange());
   }
}

Let us compile and run the above program, this will produce the following result −

Sat Nov 19 16:24:47 IST 2022
Gregorian Change DateSun Jan 10 00:00:00 IST 1993
java_util_gregoriancalendar.htm
Advertisements