user3173015
user3173015

Reputation:

Storing a date with LocalDate

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

Answers (2)

soorapadman
soorapadman

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

Kunal_89
Kunal_89

Reputation: 309

Try this-

LocalDate today = LocalDate.now();
LocalDate tomorrow = today.plus(1, ChronoUnit.DAYS);
LocalDate yesterday = tomorrow.minusDays(2);

Upvotes: 1

Related Questions