带有示例的Java中的 HijrahChronology dateNow(Clock) 方法
Java.time.chrono.HijrahChronology类的dateNow()方法用于根据 Hijrah 日历系统从指定的时钟对象中获取当前的本地日期。
句法:
public HijrahDate dateNow(Clock clock)
参数:该方法以时钟对象为参数。
返回值:该方法根据Hijrah日历系统从指定的时钟对象返回本地日期。
以下是说明dateNow()方法的示例:
示例 1:
// Java program to demonstrate
// dateNow() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] argv)
{
try {
// creating and initializing HijrahDate Object
HijrahDate hidate = HijrahDate.now();
// getting HijrahChronology used in HijrahDate
HijrahChronology crono = hidate.getChronology();
// creating and initializing clock object
Clock clock = Clock.systemUTC();
// getting HijrahDate for the
// given clock object
// by using dateNow() method
HijrahDate date = crono.dateNow(clock);
// display the result
System.out.println("HijrahDate is: " + date);
}
catch (DateTimeException e) {
System.out.println("passed parameter can "
+ "not form a date");
System.out.println("Exception thrown: " + e);
}
}
}
输出:
HijrahDate is: Hijrah-umalqura AH 1441-05-27
示例 2:
// Java program to demonstrate
// dateNow() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] argv)
{
try {
// creating and initializing HijrahDate Object
HijrahDate hidate = HijrahDate.now();
// getting HijrahChronology used in HijrahDate
HijrahChronology crono = hidate.getChronology();
// creating and initializing clock object
Clock clock = Clock.systemUTC();
// setting clock
clock = Clock.tick(clock,
Duration.ofDays(100));
// getting HijrahDate for the
// given clock object
// by using dateNow() method
HijrahDate date = crono.dateNow(clock);
// display the result
System.out.println("HijrahDate is: " + date);
}
catch (DateTimeException e) {
System.out.println("passed parameter can "
+ "not form a date");
System.out.println("Exception thrown: " + e);
}
}
}
输出:
HijrahDate is: Hijrah-umalqura AH 1441-03-03
参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/HijrahChronology.html#dateNow-java.time.Clock-