📌  相关文章
📜  Java中的 ThaiBuddhistDate minus(long, TemporalUnit) 方法

📅  最后修改于: 2022-05-13 01:54:19.056000             🧑  作者: Mango

Java中的 ThaiBuddhistDate minus(long, TemporalUnit) 方法

Java.time.chrono.ThaiBuddhistDate类的minus()方法用于在从当前 ThaiBuddhist 日期中减去一定数量的时间访问器单元后获取 ThaiBuddhist 日期。

句法:

public ThaiBuddhistDate minus(
           long amountToSubtract,
           TemporalUnit unit)

参数:此方法将以下参数作为参数:

  • amountToSubtract:这是将从当前 ThaiBuddhist 日期中减去的时间单位的值。
  • unit:时间单位或计时单位的对象。

返回值:此方法在从当前 ThaiBuddhist 日期中减去一定数量的时间访问器单元后返回 ThaiBuddhist 日期。

以下是说明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
            // ThaiBuddhistDate Object
            ThaiBuddhistDate hidate
                = ThaiBuddhistDate.now();
 
            // Display the result
            System.out.println(
                "Old ThaiBuddhist date: "
                + hidate);
 
            // Subtracting ThaiBuddhist date
            // by using minus() method
            ThaiBuddhistDate newdate
                = hidate.minus(
                    22, ChronoUnit.DAYS);
 
            // Display the result
            System.out.println(
                "New ThaiBuddhist 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
            // ThaiBuddhistDate Object
            ThaiBuddhistDate hidate
                = ThaiBuddhistDate.now();
 
            // Display the result
            System.out.println(
                "Old ThaiBuddhist date: "
                + hidate);
 
            // Subtracting ThaiBuddhist date
            // by using minus() method
            ThaiBuddhistDate newdate
                = hidate.minus(
                    4, ChronoUnit.DECADES);
 
            // Display the result
            System.out.println(
                "New ThaiBuddhist date: "
                + newdate);
        }
        catch (DateTimeException e) {
 
            System.out.println(
                "Passed parameter can"
                + " not form a date");
 
            System.out.println(
                "Exception thrown: "
                + e);
        }
    }
}


输出:
Old ThaiBuddhist date: ThaiBuddhist BE 2563-05-03
New ThaiBuddhist date: ThaiBuddhist BE 2563-04-11

示例 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
            // ThaiBuddhistDate Object
            ThaiBuddhistDate hidate
                = ThaiBuddhistDate.now();
 
            // Display the result
            System.out.println(
                "Old ThaiBuddhist date: "
                + hidate);
 
            // Subtracting ThaiBuddhist date
            // by using minus() method
            ThaiBuddhistDate newdate
                = hidate.minus(
                    4, ChronoUnit.DECADES);
 
            // Display the result
            System.out.println(
                "New ThaiBuddhist date: "
                + newdate);
        }
        catch (DateTimeException e) {
 
            System.out.println(
                "Passed parameter can"
                + " not form a date");
 
            System.out.println(
                "Exception thrown: "
                + e);
        }
    }
}
输出:
Old ThaiBuddhist date: ThaiBuddhist BE 2563-05-03
New ThaiBuddhist date: ThaiBuddhist BE 2523-05-03

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/chrono/ThaiBuddhistDate.html#minus-long-java.time.temporal.TemporalUnit-