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


Java JapaneseDate plus(long, TemporalUnit)用法及代码示例


java.time.chrono.JapaneseDate类的plus()方法用于在将一定数量的临时访问器单元与当前日语日期相加后获取日语日期。

用法:

public JapaneseDate plus(long amountToAdd,
                         TemporalUnit unit)

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

  • amountToAdd:这是将与当前日语日期相加的时间单位的数量。
  • unit:这是时间单位或计时单位的对象。

返回值:此方法在将一定数量的临时访问器单位与当前日语日期相加后返回日语日期。

下面是说明plus()方法的示例:



范例1:

Java

// Java program to demonstrate 
// plus() 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 
            // JapaneseDate Object 
            JapaneseDate hidate 
                = JapaneseDate.of( 
                    4000, 06, 23); 
  
            // Display the result 
            System.out.println( 
                "Old Japanese date:"
                + hidate); 
  
            // Adding some amount in Japanese date 
            // by using plus() method 
            JapaneseDate newdate 
                = hidate.plus( 
                    22, 
                    ChronoUnit.DAYS); 
  
            // Display the result 
            System.out.println( 
                "New Japanese date:"
                + newdate); 
        } 
        catch (DateTimeException e) { 
  
            System.out.println( 
                "Passed parameter can"
                + " not form a date"); 
  
            System.out.println( 
                "Exception thrown:"
                + e); 
        } 
    } 
}
输出:
Old Japanese date:Japanese Heisei 2012-06-23
New Japanese date:Japanese Heisei 2012-07-15

范例2:

Java

// Java program to demonstrate 
// plus() 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 
            // JapaneseDate Object 
            JapaneseDate hidate 
                = JapaneseDate.of( 
                    4000, 06, 23); 
  
            // Display the result 
            System.out.println( 
                "Old Japanese date:"
                + hidate); 
  
            // Adding some amount in Japanese date 
            // by using minus() method 
            JapaneseDate newdate 
                = hidate.plus( 
                    6, 
                    ChronoUnit.YEARS); 
  
            // Display the result 
            System.out.println( 
                "New Japanese date:"
                + newdate); 
        } 
        catch (DateTimeException e) { 
  
            System.out.println( 
                "Passed parameter can"
                + " not form a date"); 
  
            System.out.println( 
                "Exception thrown:"
                + e); 
        } 
    } 
}
输出:
Old Japanese date:Japanese Heisei 2012-06-23
New Japanese date:Japanese Heisei 2018-06-23

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




相关用法


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