Java ChronoPeriod getChronology()方法及示例

来源:这里教程网 时间:2026-02-17 20:41:13 作者:

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

程序2 :

// 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-

相关推荐