使用LocalDate存储日期

时间:2016-01-21 07:35:26

标签: java date

我正在尝试在LocalDate对象中存储上一个日期,但我不确定如何。 到目前为止,我一直在使用自己的类,但我想应用java.time.LocalDate库。 帮助

我的代码:     LocalDate theDate = new LocalDate(theYear,theMonth,theDay);

错误讯息:     LocalDate theDate = new LocalDate(theYear,theMonth,theDay);

2 个答案:

答案 0 :(得分:2)

试试这样:

Java 8 java.time.LocalDate类没有公共构造函数,

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);
    }



}

答案 1 :(得分:1)

试试这个 -

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