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
相关用法
- Java JapaneseDate minus(long, TemporalUnit)用法及代码示例
- Java JapaneseDate from()用法及代码示例
- Java JapaneseDate of(int, int, int)用法及代码示例
- Java JapaneseDate isSupported()用法及代码示例
- Java JapaneseDate getLong()用法及代码示例
- Java JapaneseDate toString()用法及代码示例
- Java JapaneseDate range()用法及代码示例
- Java JapaneseDate toEpochDay()用法及代码示例
- Java JapaneseDate hashCode()用法及代码示例
- Java JapaneseDate of(JapaneseEra,int, int, int)用法及代码示例
- Java JapaneseDate equals()用法及代码示例
- Java JapaneseDate atTime()用法及代码示例
- Java JapaneseDate getEra()用法及代码示例
- Java JapaneseDate getChronology()用法及代码示例
- Java JapaneseDate lengthOfYear()用法及代码示例
- Java JapaneseDate now(Clock)用法及代码示例
- Java JapaneseDate lengthOfMonth()用法及代码示例
- Java JapaneseDate now(ZoneId)用法及代码示例
- Java Duration get(TemporalUnit)用法及代码示例
- Java MinguoDate plus(long, TemporalUnit)用法及代码示例
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 JapaneseDate plus(long, TemporalUnit) method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。