Java中的 MinguoDate now(ZoneId) 方法及示例
Java.time.chrono.MinguoDate类的now()方法用于根据指定区域的民国日历系统获取当前民国日期。
句法:
public static MinguoDate now(ZoneId zone)
参数:此方法获取区域id的对象,根据该对象将形成民国日期。
返回值:该方法根据民国日历系统从指定时钟返回当前民国日期。
下面是说明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 ZoneId
ZoneId id = ZoneId.systemDefault();
// Creating and initializing
// MinguoDate Object
MinguoDate hidate
= MinguoDate.now(id);
// 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 ZoneId
ZoneId id = ZoneId.of("Z");
// Creating and initializing
// MinguoDate Object
MinguoDate hidate
= MinguoDate.now(id);
// 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 ZoneId
ZoneId id = ZoneId.of("Z");
// Creating and initializing
// MinguoDate Object
MinguoDate hidate
= MinguoDate.now(id);
// 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.ZoneId-