JSF is converting all date/datetime types into GMT base for rendering. This can cause a date offset of n-hours to be shown depending on the timezone you are in. You have 2 choices to deal with it: Either you implement an application wide (global) date converter as described here or you add the timezone attribute to each of the convertDateTime tags.

1
2
3
<h:outputText value="#{day.date}">
  <f:convertDateTime type="date" pattern="dd.MM.yyyy" timeZone="#{viewController.timeZoneId}"/>
</h:outputText>

The latter approach allows to have a single point of detecting a users timezone preference (unfortunately the timezone is not included in the HTTP header) but requires to have the timezone attribute implemented in multiple places.

So far so good. Many solutions propose using the timezone offset based timezone identifier which turns out to be bad. It doesn’t allow the JDK date formatters to properly apply the daylight settings. So better use “Europe/Vienna” instead of “GMT+1”. It even looks like there were some subtle changes with turning from JDK 1.5 to JDK 1.6 regarding this.

Comments