简体   繁体   English

Struts2 Ognl标记中的日期比较

[英]Date comparison in Struts2 Ognl tags

My requirement is to display a date from db and the status message to inform whether the date coming from db is past date, current date or a future date. 我的要求是显示db的日期和状态消息,以通知来自db的日期是过去日期,当前日期还是将来的日期。

I'm displaying the date from db by 我正在显示db的日期

<s:property value="%{selObj.lastdate}"/>

Now how to get the current date in OGNL tags, I have tried 现在,我试过如何获取OGNL标签中的当前日期

<s:propery value="%{new Date()}"/>

I need this current date to compare with selObj.lastdate and find out the date is passed? 我需要这个当前日期与selObj.lastdate进行比较,并找出日期已通过?

要获取当前日期/时间,您不需要修改您的操作类,只需将此行添加到您的jsp:

<s:property value="@java.util.Calendar@getInstance().time" />

If you can modify your action side:

You can try to write a getter as like: 您可以尝试编写一个getter,如:

public Date getCurrentDate(){
    return new Date();
} 

at your Java(Action) side. 在Java(Action)方面。

So you can get that value: 所以你可以得到这个价值:

<s:property value="currentDate"/>

at your JSP side. 在您的JSP端。

That's is the right way to compare and get current date. 这是比较和获取当前日期的正确方法。 I have to suggest to display a date in UI, should use like this; 我必须建议在UI中显示日期,应该像这样使用;

<s:date name="currentDate"  format="dd-MM-yyyy" />

It will be formatted date. 它将格式化日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM