📌  相关文章
📜  Java中的 MinguoDate now() 方法与示例

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

Java中的 MinguoDate now() 方法与示例

Java.time.chrono.MinguoDate类的now()方法用于根据民国日历系统从指定时钟获取当前民国日期。

句法:

public static MinguoDate now(Clock clock)

参数:此方法获取时钟对象,在此基础上形成民国日期。

返回值:该方法根据民国日历系统从指定时钟返回当前民国日期。

下面是说明now()方法的示例:示例 1:

Java
// Java program to demonstrate now() method
  
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        try {
            // Creating and initializing clock
            Clock clock = Clock.systemUTC();
  
            // Creating and initializing
            // MinguoDate Object
            MinguoDate hidate
                = MinguoDate.now(clock);
  
            // Display the result
            System.out.println("MinguoDate: "
                               + hidate);
        }
        catch (DateTimeException e) {
            System.out.println("passed parameter can"
                               + " not form a date");
            System.out.println("Exception thrown: "
                               + e);
        }
    }
}


Java
// Java program to demonstrate now() method
  
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        try {
            // Creating and initializing clock
            Clock clock = Clock.systemDefaultZone();
  
            // Creating and initializing
            // MinguoDate Object
            MinguoDate hidate
                = MinguoDate.now(clock);
  
            // Display the result
            System.out.println("MinguoDate: "
                               + hidate);
        }
        catch (DateTimeException e) {
            System.out.println("passed parameter can"
                               + " not form a date");
            System.out.println("Exception thrown: "
                               + e);
        }
    }
}


输出:
MinguoDate: Minguo ROC 109-04-24

示例 2:

Java

// Java program to demonstrate now() method
  
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        try {
            // Creating and initializing clock
            Clock clock = Clock.systemDefaultZone();
  
            // Creating and initializing
            // MinguoDate Object
            MinguoDate hidate
                = MinguoDate.now(clock);
  
            // Display the result
            System.out.println("MinguoDate: "
                               + hidate);
        }
        catch (DateTimeException e) {
            System.out.println("passed parameter can"
                               + " not form a date");
            System.out.println("Exception thrown: "
                               + e);
        }
    }
}
输出:
MinguoDate: Minguo ROC 109-04-24

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/MinguoDate.html#now-java.time.Clock-