📌  相关文章
📜  Java中的 ChronoPeriod getChronology() 方法及示例

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

Java中的 ChronoPeriod getChronology() 方法及示例

Java中ChronoPeriod接口getChronology()方法用来获取这个Period的年表,也就是ISO日历系统。

句法:

ChronoPeriod getChronology()

参数:此方法不接受任何参数。

返回值:此方法返回此的字符串表示

下面的程序说明了上述方法:

程序 1

// Java code to show the getChronology() function
  
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.ChronoUnit;
  
public class ChronoPeriodClass {
  
    // Function to negate given periods
    static void printChronology(ChronoPeriod p1)
    {
  
        System.out.println(p1.getChronology());
    }
  
    // Driver Code
    public static void main(String[] args)
    {
        // Defining period
        int year = 4;
        int months = 11;
        int days = 10;
        ChronoPeriod p1 = Period.of(year, months, days);
  
        printChronology(p1);
    }
}
输出:
ISO

方案二

// Java code to show the getChronology() function
  
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.ChronoUnit;
  
public class ChronoPeriodClass {
  
    // Function to negate given periods
    static void printChronology(ChronoPeriod p1)
    {
  
        System.out.println(p1.getChronology());
    }
  
    // Driver Code
    public static void main(String[] args)
    {
        // Defining period
        int year = -4;
        int months = -11;
        int days = -10;
        ChronoPeriod p1 = Period.of(year, months, days);
  
        printChronology(p1);
    }
}
输出:
ISO

参考:https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/ChronoPeriod.html#getChronology–