我试着用from.isBefore(to)
检查一周是否结束了。来自LocalDate(例如今天)和from.plusDays(6)
,所以一周。现在的问题是它始终是真的。我如何修复toDate
,fromDate
只是计数并且在达到if条件后做某事?
LocalDate from = LocalDate.now();
LocalDate to = from.withPeriodAdded(Period.days(6), 1);
if(from.isBefore(to)) {
//do something;
}....
如果你有from
,并且你通过在to
增加6天计算from
,from
将始终在之前(并且from.isBefore(to)
将始终返回True
)。您需要明确检查两个日期之间的差异是否为7天。
看看静态的daysBetween(ReadableInstant start, ReadableInstant end)
方法。
好的,我解决了。我在我的日常文件中写了当前的LocalDate。然后我用index.Of从File中读取String并将其解析为LocalDate。我添加了这个Date 6 Days和来自CurrentDate的计数器。也许这不是最好的解决方案,但它有效......
//In my Async-Class where the Files get written
LocalDate currentDate = LocalDate.now();
outputStream.write(currentDate.toString().getBytes());
//In my Main-clasS
final LocalDate currentDate = LocalDate.now(); //Current Date
final int daysbetween = 6; //days between current date and date of file
final int index = openfilewed().indexOf("2", 30); //Date from file
final LocalDate[] filedate = new LocalDate[1];
final LocalDate[] reach = new LocalDate[1];
filedate[0] = LocalDate.parse(openfilemon().substring(index));
reach[0] = filedate[0].plusDays(daysbetween);
if (currentDate.isBefore(reach[0])){
//do something
}