private Instant submissionDate = Instant.now();
void scheduleResult() {
if(submissionDate befor 30 min)
execute;
}
如果submisisionDate早于30分钟,如何执行调度程序任务。
答案 0 :(得分:2)
使用Instant#minus(30, ChronoUnit.MINUTES)
Instant submissionDate = ...
Instant now = Instant.now();
Instant thirtyMinutesBeforeNow = now.minus(30, ChronoUnit.MINUTES);
if (submissionDate.isBefore(thirtyMinutesBeforeNow)) {
}
Instant submissionDate = ...
Instant now = Instant.now();
Instant thirtyMinutesBeforeNow = now.minusSeconds(1800);
if (submissionDate.isBefore(thirtyMinutesBeforeNow)) {
}
答案 1 :(得分:1)
您可以在过去的日期中激活30分钟:
LocalDateTime halfHourInPast = LocalDateTime.now().minusMinutes(30);
并使用它来比较您的日期:
LocalDateTime submissionDate = LocalDateTime.ofInstant(submissionDateInstant, ZoneOffset.UTC);
if(submissionDate.isBefore(halfHourInPast)){
//schedule
}
答案 2 :(得分:1)
if ( submissionDate.isBefore(Instant.now().minus(30, ChronoUnit.MINUTES))){
// run
}