当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java MinguoDate minus(long, TemporalUnit)用法及代码示例


java.time.chrono.MinguoDate类的minus()方法用于在从当前Minguo日期中减去一定数量的词性访问器单位后获取Minguo日期。

用法:

public MinguoDate minus(long amountToAdd,
                        TemporalUnit unit)

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



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

返回值:此方法从当前的Mining日期减去临时访问者单位的数量后返回Minguo日期。

下面是说明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); 
  
            // Substracting 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); 
        } 
    } 
}
输出:
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); 
  
            // Substracting 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-




相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 MinguoDate minus(long, TemporalUnit) method in Java with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。