Home » Java programming language

Java GregorianCalendar setGregorianChange() Method with Example

GregorianCalendar Class setGregorianChange() method: Here, we are going to learn about the setGregorianChange() method of GregorianCalendar Class with its syntax and example.
Submitted by Preeti Jain, on February 15, 2020

GregorianCalendar Class setGregorianChange() method

  • setGregorianChange() method is available in java.util package.
  • setGregorianChange() method is used to assign the GregorianCalendar change date from Julian to gregorian dates.
  • setGregorianChange() method is a non-static method, so it is accessible with the class object and if we try to access the method with the class name then we will get an error.
  • setGregorianChange() method does not throw an exception at the time of the set gregorian calendar date.

Syntax:

    public void setGregorianChange(Date d);

Parameter(s):

  • Date d – represent the GregorianCalendar date.

Return value:

The return type of the method is void, it returns nothing.

Example:

// Java program is to demonstrate the example of
// setGregorianChange(Date d) method of Calendar

import java.util.*;

public class SetGregorianChange {
    public static void main(String[] args) {
        // Instantiates a GregorianCalendar object
        GregorianCalendar ca = (GregorianCalendar) GregorianCalendar.getInstance();
        Date d = new Date(98, 04, 20);

        // Display current GregorianCalendar
        System.out.println("ca: " + ca.getTime());

        // By using getGregorianChange() method isto
        // change the gregorian calendar date
        System.out.print("ca.getGregorianChange(): ");
        System.out.println(ca.getGregorianChange());

        // By using setGregorianChage() method isto
        // set the GregorianChange date
        ca.setGregorianChange(d);

        // By using getGregorianChange() method isto
        // get the change gregorian calendar date
        System.out.print("ca.setGregorianChange(d): ");
        System.out.println(ca.getGregorianChange());
    }
}

Output

ca: Sat Feb 15 12:53:31 GMT 2020
ca.getGregorianChange(): Fri Oct 15 00:00:00 GMT 1582
ca.setGregorianChange(d): Wed May 20 00:00:00 GMT 1998


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.