yrazlik
yrazlik

Reputation: 10777

How to display java.util.Date in 2013-07-15 22:00:45 format

I have a variable stored in TIMESTAMP format in db. It stores time like this:

2013-07-15 22:00:45

I want to take this and use it in a h:outputText item. I make a database search, and store the results in a resultset.

java.util.Date dt= res.getTimestamp(5);

Then i want to use this date, which was read from database, in an outputtext item. But doing the following does not work:

<h:outputText value="#{list.date}"

Where list is an ArrayList. I am sure that list.date is the date I read from database but I cannot get its value with the format I specified. So how can I do this?

Upvotes: 0

Views: 1432

Answers (2)

Philippe
Philippe

Reputation: 6828

I guess you can use JSF's convertDateTime tag.

e.g. :

<h:outputText value="#{list.date}">
    <f:convertDateTime pattern="d-M-yyyy" />
</h:outputText>

See http://www.jsftoolbox.com/documentation/help/12-TagReference/core/f_convertDateTime.html

Upvotes: 2

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51711

<h:outputText value="#{list.date}">
    <f:convertDateTime type="both" pattern="YYYY-MM-dd HH:mm:ss"/>
</h:outputText>

Upvotes: 3

Related Questions