“plusDays” doesn't advance LocalDate in Java 8

给你一囗甜甜゛ 提交于 2019-12-01 07:45:39

问题


Why is LocalDate not changing even though there is no error during running?

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse("2005-12-12", formatter);
date.plusDays(3);
System.out.println(date.toString());

Output:

2005-12-12

Anything I missed out?


回答1:


LocalDate is immutable

date = date.plusDays(3);



回答2:


As a String, it doesn't have an effect calling a method on it without assigning the result :

date = date.plusDays(3);

Read More



来源:https://stackoverflow.com/questions/33333201/plusdays-doesnt-advance-localdate-in-java-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!