开发者

Date comparison in Struts2 Ognl tags

开发者 https://www.devze.com 2023-02-25 05:44 出处:网络
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.

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.

I'm displaying the date from db by

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

Now how to get the current date in OGNL tags, I have tried

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

I need this current da开发者_Python百科te to compare with selObj.lastdate and find out the date is passed?


If you can modify your action side:

You can try to write a getter as like:

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

at your Java(Action) side.

So you can get that value:

<s:property value="currentDate"/>

at your JSP side.


To get the current date/time, you won't need to modify your action class, just add this line to your jsp:

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


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;

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

It will be formatted date.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号