Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Tuesday, October 23, 2007

Date is displayed wrong-decrease 1 day(JSF)

Have you ever get confused because your Date is displayed wrong (i.e. decreased 1 day) when you use h:outputText?
This might happen because JSF spec says that date converter defaults to using standard UTC timezone and you're happen to live in some other timezone, in my case it is GMT+07.

My first idea was to build a date converter which use the default timezone in the server and use f:converter to specify my converter id. Somehow the date pattern can't be passed to my converter, that's sad, I don't want to force a certain pattern.

My second idea is simply to create a method in my utility bean called
public String getTimeZone() which will return the default timezone ID, and use it to specify the timezone attribute in f:convertDateTime facet.

so the outcome looks like this :
<h:outputText value="#{track.movedDate}">
<f:convertDateTime pattern="MM/dd/yyyy" type="date" timeZone="#{constants.timeZone}"/>
</h:outputText>

All that needs to be done is to put the convertDateTime facet in every outputText.