SkyvrawleR
SkyvrawleR

Reputation: 412

"plusDays" doesn't advance LocalDate in Java 8

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?

Upvotes: 2

Views: 1590

Answers (2)

Yassin Hajaj
Yassin Hajaj

Reputation: 21975

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

date = date.plusDays(3);

Read More

Upvotes: 1

Reimeus
Reimeus

Reputation: 159794

LocalDate is immutable

date = date.plusDays(3);

Upvotes: 10

Related Questions