Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the date pattern on jsf pages?

Tags:

jsf

jsf-2

<rich:column>
    <f:facet name="header">
          <h:outputText value="Expiry Date"/>
    </f:facet>
    <h:outputText value="#{item.endDate}">

    </h:outputText>
</rich:column>

Using above code, I got the date from database is 2012-09-03 00:00:00.0

Now, I want to set the date pattern to dd-MM-yyyy.

So my required output is 03-09-2012.

But using below code (after setting the pattern)

<rich:column>
     <f:facet name="header">
         <h:outputText value="Expiry Date"/>
     </f:facet>
     <h:outputText value="#{item.endDate}">
          <f:convertDateTime pattern="dd-MM-yyyy"  />
     </h:outputText>
</rich:column>

I am getting the output is 02-09-2012

Whatever date is in database, it shows output less by one day.

In advance thanks.

like image 834
pioneer Avatar asked Nov 13 '22 15:11

pioneer


1 Answers

You should add suitable timeZone attribute to convertDateTime component. For an example in my zone

<f:convertDateTime pattern="dd-MM-yyyy" timeZone="Asia/Calcutta" />

Note:

you can use java.util.TimeZone.getDefault().getID() to get your current time zone id.

like image 97
prageeth Avatar answered Nov 15 '22 10:11

prageeth