带有示例的Java中的 HijrahDate minus(long, TemporalUnit) 方法
Java.time.chrono.HijrahDate类的minus()方法用于在从当前回历日期中减去一定数量的时间访问器单元后获取回历日期。
句法:
public HijrahDate minus(long amountToSubtract,
TemporalUnit unit)
参数:此方法将以下参数作为参数:
- amountToSubtract:这是要从当前 hijrah 日期中减去的时间单位的值。
- 单位:这是时间单位或计时单位的对象。
返回值:此方法在从当前 Hijrah日期中减去一定数量的时间访问器单元后返回 Hijrah 日期。
以下是说明minus()方法的示例:
示例 1:
Java
// Java program to demonstrate minus() 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
// HijrahDate Object
HijrahDate hidate = HijrahDate.now();
// Display the result
System.out.println("old hijrah date: "
+ hidate);
// Subtracting hijrah date
// by using minus() method
HijrahDate newdate
= hidate.minus(
22, ChronoUnit.DAYS);
// Display the result
System.out.println("new hijrah date: "
+ newdate);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown: "
+ e);
}
}
}
Java
// Java program to demonstrate minus() 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 {
// Dreating and initializing
// HijrahDate Object
HijrahDate hidate
= HijrahDate.now();
// Display the result
System.out.println("old hijrah date: "
+ hidate);
// Subtracting hijrah date
// by using minus() method
HijrahDate newdate
= hidate.minus(
4, ChronoUnit.DECADES);
// Display the result
System.out.println("new hijrah date: "
+ newdate);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown: "
+ e);
}
}
}
输出:
old hijrah date: Hijrah-umalqura AH 1441-06-25
new hijrah date: Hijrah-umalqura AH 1441-06-03
示例 2:
Java
// Java program to demonstrate minus() 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 {
// Dreating and initializing
// HijrahDate Object
HijrahDate hidate
= HijrahDate.now();
// Display the result
System.out.println("old hijrah date: "
+ hidate);
// Subtracting hijrah date
// by using minus() method
HijrahDate newdate
= hidate.minus(
4, ChronoUnit.DECADES);
// Display the result
System.out.println("new hijrah date: "
+ newdate);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown: "
+ e);
}
}
}
输出:
old hijrah date: Hijrah-umalqura AH 1441-06-25
new hijrah date: Hijrah-umalqura AH 1401-06-25
参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/HijrahDate.html#minus-long-java.time.temporal.TemporalUnit-