带有示例的Java中的 HijrahDate isLeapYear() 方法
Java.time.chrono.HijrahDate类的isLeapYear()方法用于区分闰年和非闰年。如果此 HijrahDate 表示的年份是闰年,则此方法将返回 true,否则返回 false。
句法:
public boolean isLeapYear()
参数:此方法不接受任何参数作为参数。
返回值:此方法返回布尔值,即如果预测年是闰年则为真,否则为假。
下面是说明isLeapYear()方法的示例:
示例 1:
Java
// Java program to demonstrate
// isLeapYear() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] argv)
{
// Creating and initializing
// HijrahDate Object
HijrahDate hidate
= HijrahDate.of(1398, 03, 23);
System.out.println("HijrahDate: "
+ hidate.toString());
// Checking if the date is leap year or not
// by using isLeapYear() method
boolean flag = hidate.isLeapYear();
// Display the result
if (flag)
System.out.println("Leap year");
else
System.out.println("Not a leap year");
}
}
Java
// Java program to demonstrate
// isLeapYear() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] argv)
{
// Creating and initializing
// HijrahDate Object
HijrahDate hidate = HijrahDate.now();
System.out.println("HijrahDate: "
+ hidate.toString());
// Checking if the date is leap year or not
// by using isLeapYear() method
boolean flag = hidate.isLeapYear();
// Display the result
if (flag)
System.out.println("Leap year");
else
System.out.println("Not a leap year");
}
}
输出:
HijrahDate: Hijrah-umalqura AH 1398-03-23
Not a leap year
示例 2:
Java
// Java program to demonstrate
// isLeapYear() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] argv)
{
// Creating and initializing
// HijrahDate Object
HijrahDate hidate = HijrahDate.now();
System.out.println("HijrahDate: "
+ hidate.toString());
// Checking if the date is leap year or not
// by using isLeapYear() method
boolean flag = hidate.isLeapYear();
// Display the result
if (flag)
System.out.println("Leap year");
else
System.out.println("Not a leap year");
}
}
输出:
HijrahDate: Hijrah-umalqura AH 1441-06-25
Leap year
参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/HijrahDate.html#isLeapYear–