Java GregorianCalendar - setGregorianChange() Method
The java.util.GregorianCalendar.setGregorianChange() method is used to set 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.
To obtain a pure Julian calendar, set the change date to Date(Long.MAX_VALUE). To obtain a pure Gregorian calendar, set the change date to Date(Long.MIN_VALUE).
Syntax
public void setGregorianChange(Date date)
Parameters
date |
Specify the given Gregorian cutover date. |
Return Value
void type.
Exception
NA.
Example:
In the example below, the java.util.GregorianCalendar.setGregorianChange() method is used to set the GregorianCalendar change date.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a Calendar object with specified date GregorianCalendar Cal = new GregorianCalendar(2015, 10, 30); //printing the Calendar System.out.println("The Calendar is: " + Cal.getTime()); //printing the default GregorianCalendar change date System.out.println("\nDefault GregorianCalendar change date: "); System.out.println(Cal.getGregorianChange()); //change the GregorianCalendar change date GregorianCalendar cal1 = new GregorianCalendar(1995, 10, 30); Date Dt = cal1.getTime(); Cal.setGregorianChange(Dt); //printing the modified GregorianCalendar change date System.out.println("\nModified GregorianCalendar change date: "); System.out.println(Cal.getGregorianChange()); } }
The output of the above code will be:
The Calendar is: Mon Nov 30 00:00:00 UTC 2015 Default GregorianCalendar change date: Fri Oct 15 00:00:00 UTC 1582 Modified GregorianCalendar change date: Thu Nov 30 00:00:00 UTC 1995
❮ Java.util - GregorianCalendar