Java中的Period withDays()方法
使用withDays()Java的Period类中的方法完成了具有所需天数的Period的不可变副本。此方法需要一个参数,即“期间”中的天数,并根据需要返回“天数”和“天数”。
演示此程序如下
示例
import java.time.Period;
public class Demo {
public static void main(String[] args) {
String period = "P5Y7M15D";
Period p1 = Period.parse(period);
System.out.println("The Period is: " + p1);
Period p2 = p1.withDays(3);
System.out.println("The Period with days altered to 3 is: " + p2);
}
}输出结果
The Period is: P5Y7M15D The Period with days altered to 3 is: P5Y7M3D
现在让我们了解上面的程序。
首先显示期间。然后使用方法显示将天数更改为3的期间withDays()。演示此代码段如下所示:
String period = "P5Y7M15D";
Period p1 = Period.parse(period);
System.out.println("The Period is: " + p1);
Period p2 = p1.withDays(3);
System.out.println("The Period with days altered to 3 is: " + p2);热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下