0
我想使用標準API將登錄用戶的當前日期(根據他的時區)與表列進行比較。在java中使用Criteria Builder API的日期比較
但我無法從我爲用戶計算的本地日期中獲取表達式。我該如何解決這個問題?
public void checkTaskCategory(TaskCriteria criteria, CriteriaBuilder cb, CriteriaQuery<Task> q, Root<Task> task, List<Predicate> predicates) {
if (StringUtils.isNotBlank(criteria.getCategory())) {
LocalDate currentDateForUserTimezone = LocalDateTime.now(ZoneId.of("Pacific/Pago_Pago")).toLocalDate();
if (StringUtils.equalsIgnoreCase(TaskConstants.TASK_OVERDUE, criteria.getCategory())) {
predicates.add(cb.greaterThan(cb.currentDate(), task.<Date>get(TaskConstants.DUE_DATE)));
predicates.add(cb.notEqual(task.get("status"), getStatus(Status.Value.DONE.toString()).getId()));
q.orderBy(cb.asc(task.get(TaskConstants.DUE_DATE)));
}
}
}
我要替換cb.currentDate()
我以來cb.currentDate
比較沒有考慮到時區計算currentDateForUserTimezone
。我怎樣才能實現它?
@lonut你知道嗎? –
與您的問題無關,但您可以使用'LocalDate.now(ZoneId.of(「Pacific/Pago_Pago」))''。它相當於(但比它短)'LocalDateTime.now(ZoneId.of(「Pacific/Pago_Pago」))。toLocalDate()' – 2017-09-15 17:04:09
@ Hugo ..謝謝。 –