MinguoDate minus(long, TemporalUnit) 方法在Java中的示例
Java.time.chrono.MinguoDate类的minus()方法用于在从当前民国日期中减去一定数量的临时访问器单元后得到民国日期。
句法:
public MinguoDate minus(long amountToAdd,
TemporalUnit unit)
参数:此方法将以下参数作为参数:
- amountToSubtract:这是要从当前民国日期中减去的时间单位的值。
- 单位:这是时间单位或计时单位的对象。
返回值:该方法在从当前民国日期中减去一定数量的临时访问器单元后返回民国日期。
以下是说明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
// MinguoDate Object
MinguoDate hidate = MinguoDate.now();
// Display the result
System.out.println("old Minguo date: "
+ hidate);
// Subtracting Minguo date
// by using minus() method
MinguoDate newdate
= hidate.minus(
22, ChronoUnit.DAYS);
// Display the result
System.out.println("new Minguo 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 {
// Creating and initializing
// MinguoDate Object
MinguoDate hidate = MinguoDate.now();
// Display the result
System.out.println("old Minguo date: "
+ hidate);
// Subtracting Minguo date
// by using minus() method
MinguoDate newdate
= hidate.minus(
4, ChronoUnit.DECADES);
// Display the result
System.out.println("new Minguo date: "
+ newdate);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown: "
+ e);
}
}
}
输出:
old Minguo date: Minguo ROC 109-04-24
new Minguo date: Minguo ROC 109-04-02
示例 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 {
// Creating and initializing
// MinguoDate Object
MinguoDate hidate = MinguoDate.now();
// Display the result
System.out.println("old Minguo date: "
+ hidate);
// Subtracting Minguo date
// by using minus() method
MinguoDate newdate
= hidate.minus(
4, ChronoUnit.DECADES);
// Display the result
System.out.println("new Minguo date: "
+ newdate);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown: "
+ e);
}
}
}
输出:
old Minguo date: Minguo ROC 109-04-24
new Minguo date: Minguo ROC 69-04-24
参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/MinguoDate.html#minus-long-java.time.temporal.TemporalUnit-