📜  GregorianCalendar getGregorianChange() 方法

📅  最后修改于: 2022-05-13 01:54:31.918000             🧑  作者: Mango

GregorianCalendar getGregorianChange() 方法

Java.util.GregorianCalendar.getGregorianChange()是Java中的一个内置方法,它返回公历更改日期,即从儒略历日期到公历日期的更改。默认为1582 年 10 月 15 日(公历) ,但可以使用 setGregorianDate()函数将其更改为任何其他日期。所有以前的日期都出现在儒略历中。

句法:

public final Date getGregorianChange()

参数:该函数不接受任何参数。

返回值:该函数返回GregorianCalendar 实例的公历更改日期。

例子:

Input : Tue Jul 24 01:22:29 UTC 2018
Output : Fri Oct 15 00:00:00 UTC 1582

Input: Tue Jul 24 01:22:29 UTC 2018
        c.setGregorianChange(new Date());
Output : Tue Jul 24 01:22:29 UTC 2018

下面的程序说明了Java.util.GregorianCalendar.getGregorianChange()函数:
方案一:

// Java Program to illustrate getGregorianChange()
// function 
import java.io.*;
import java.util.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        // Create a new calendar
        GregorianCalendar c = (GregorianCalendar)
                     GregorianCalendar.getInstance();
  
        // Display the current date and time
        System.out.println("Current Date and Time : "
                           + c.getTime());
  
        // Fetch Gregorian change and display it
        System.out.println("Gregorian Date change :"
                           + c.getGregorianChange());
    }
}
输出:
Current Date and Time : Fri Jul 27 12:38:41 UTC 2018
Gregorian Date change :Fri Oct 15 00:00:00 UTC 1582

方案二:

// Java Program to illustrate getGregorianChange()
// function 
  
import java.io.*;
import java.util.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        // Create a new calendar
        GregorianCalendar c = (GregorianCalendar)
                     GregorianCalendar.getInstance();
  
        // Display the current date and time
        System.out.println("Current Date and Time : "
                           + c.getTime());
  
        // Change to current date
        c.setGregorianChange(new Date());
  
        // Fetch and Display the result
        System.out.println("Gregorian Date change :"
                           + c.getGregorianChange());
    }
}
输出:
Current Date and Time : Fri Jul 27 12:38:44 UTC 2018
Gregorian Date change :Fri Jul 27 12:38:44 UTC 2018

参考: https: Java/util/GregorianCalendar.html#getGregorianChange()