百里香叶.如何比较日期是来自未来还是过去



我想检查Employee.dateOfCancel中的日期是否在"现在"之后。不幸的是,在运行以下代码后,我对数据一无所获:

<td> <div th:switch="${employee.dateOfTermination}"> 
                            <span th:case="'&lt; now'">CASE 1</span>
                            <span th:case="'&gt; now'" th:text="${#dates.format(employee.dateOfTermination, 'dd-MM-yyyy')}">CASE 2</span></div></td>

问题来了,百里香叶的语法对我来说确实不合适和恶心。我尝试使用 th:if,并解析一个整数。

我会这样做:

<span th:if="${employee.dateOfTermination.before(#dates.createNow())}">Case 1</span>
<span th:if="${employee.dateOfTermination.after(#dates.createNow())}">Case 2</span>

或者,如果您确实喜欢开关:

<div th:switch="${employee.dateOfTermination.before(#dates.createNow())}">
    <span th:case="true">Case 1</span>
    <span th:case="false">Case 2</span>
</div>

相关内容

最新更新