百里香叶.如何比较日期是来自未来还是过去? [英] Thymeleaf. How to compare if the date is from future, or past?
本文介绍了百里香叶.如何比较日期是来自未来还是过去?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查 Employee.dateOfTermination 中的日期是否在现在"日期之后.不幸的是,在运行以下代码后,我没有得到任何数据:
<div th:switch="${employee.dateOfTermination}"><span th:case="'< now'">CASE 1</span><span th:case="'> now'" th:text="${#dates.format(employee.dateOfTermination, 'dd-MM-yyyy')}">CASE 2</span></div></td>问题来了,thymeleaf 的语法对我来说似乎不适用和恶心.我尝试使用 th:if,并解析一个 int.
解决方案 我会这样做:
<span th:if="${employee.dateOfTermination.before(#dates.createNow())}">案例1</span><span th:if="${employee.dateOfTermination.after(#dates.createNow())}">案例2</span>
或者,如果你喜欢这个开关:
<span th:case="true">案例 1</span><span th:case="false">案例 2</span>
I want to check if the date which is in Employee.dateOfTermination is after date "now". Unfortunetely, after running following code, I get nothing on data:
<td> <div th:switch="${employee.dateOfTermination}">
<span th:case="'< now'">CASE 1</span>
<span th:case="'> now'" th:text="${#dates.format(employee.dateOfTermination, 'dd-MM-yyyy')}">CASE 2</span></div></td>
Here comes the problem, the syntax of thymeleaf does seem unappliable and disgusting for me. I tried with th:if, and parsing a int.
解决方案 I would do it like this:
<span th:if="${employee.dateOfTermination.before(#dates.createNow())}">Case 1</span>
<span th:if="${employee.dateOfTermination.after(#dates.createNow())}">Case 2</span>
Or maybe, if you do like the switch:
<div th:switch="${employee.dateOfTermination.before(#dates.createNow())}">
<span th:case="true">Case 1</span>
<span th:case="false">Case 2</span>
</div>
这篇关于百里香叶.如何比较日期是来自未来还是过去?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录
关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆