Reputation:
I am trying to store a previous date in a LocalDate object, but I am not sure how. I have been using my own class until now, but I would like to apply the java.time.LocalDate library. Help?
My code: LocalDate theDate = new LocalDate(theYear, theMonth, theDay);
Error message: LocalDate theDate = new LocalDate(theYear, theMonth, theDay);
Upvotes: 1
Views: 1827
Reputation: 4509
Try like this:
The Java 8 java.time.LocalDate class has no public constructors,
public class test {
public static void main(String[] args) {
int theYear=2016;
int theMonth=1;
int theDay=21;
LocalDate theDate = LocalDate.of(theYear,theMonth,theDay);
System.out.println(theDate);
}
}
Upvotes: 2
Reputation: 309
Try this-
LocalDate today = LocalDate.now();
LocalDate tomorrow = today.plus(1, ChronoUnit.DAYS);
LocalDate yesterday = tomorrow.minusDays(2);
Upvotes: 1