让我们首先设置一个月和天的期间:
Period p = Period.ofMonths(5).plusDays(15);
现在设置LocalDate:
LocalDate date = LocalDate.of(2019, 4, 10);
在LocalDate中添加句点:
LocalDate res = date.plus(p);
import java.time.LocalDate; import java.time.Period; public class Demo { public static void main(String[] args) { Period p = Period.ofMonths(5).plusDays(15); LocalDate date = LocalDate.of(2019, 4, 10); System.out.println("Date = "+date); LocalDate res = date.plus(p); System.out.println("Updated date = "+res); } }
输出结果
Date = 2019-04-10 Updated date = 2019-09-25