GregorianCalendar类setGregorianChange()方法 (GregorianCalendar Class setGregorianChange() method)
setGregorianChange() method is available in java.util package.
setGregorianChange()方法在java.util包中可用。
setGregorianChange() method is used to assign the GregorianCalendar change date from Julian to gregorian dates.
setGregorianChange()方法用于将GregorianCalendar更改日期从儒略日分配给gregorian日期。
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()方法是一种非静态方法,因此可以通过类对象进行访问,如果尝试使用类名称访问该方法,则会收到错误消息。
setGregorianChange() method does not throw an exception at the time of the set gregorian calendar date.
setGregorianChange()方法在设置公历日期时不会引发异常。
Syntax:
句法:
public void setGregorianChange(Date d);
Parameter(s):
参数:
Date d – represent the GregorianCalendar date.
日期d –表示公历日期。
Return value:
返回值:
The return type of the method is void, it returns nothing.
该方法的返回类型为void ,不返回任何内容。
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
翻译自: https://www.includehelp.com/java/gregoriancalendar-setgregorianchange-method-with-example.aspx