我正在尝试在LocalDate对象中存储上一个日期,但我不确定如何。 到目前为止,我一直在使用自己的类,但我想应用java.time.LocalDate库。 帮助
我的代码: LocalDate theDate = new LocalDate(theYear,theMonth,theDay);
错误讯息: LocalDate theDate = new LocalDate(theYear,theMonth,theDay);
答案 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);