Issue: The date saved when using f:convertDateTime is off by one day, or off by some number of hours.
The issue is due to the default date/time converter in JSF using GMT instead of the system’s default time zone, so you can
1) specify the time zone directly in the converter, e.g.
<f:convertDateTime pattern="MM/dd/yyyy" timeZone="#{bean.timeZone}"/>
using
in the bean (from http://www.mail-archive.com/users@myfaces.apache.org/msg27626.html), or you could
2) use a custom converter for the Date values, which looks like this:
faces-congif.xml:
<converter>
<converter-for-class>java.util.Date</converter-for-class>
<converter-class>com.coaccess.utilities.CustomDateTimeConverter</converter-class>
</converter>
com.coaccess.utilities.CustomDateTimeConverter.java:
public class CustomDateTimeConverter
extends DateTimeConverter
{
/** Constructor. */
public CustomDateTimeConverter
() {
super();
// set the default timezone to the system time zone instead of GMT
super.
setTimeZone(TimeZone.
getDefault());
setPattern
("MM/dd/yyyy");
}
}
With this second method you remove the <f:convertDateTime> from the date fields completely and the usage of <f:convertDateTime> overrides the specified default (if you don’t remove the convertDateTime tag then the specified default won’t be used and the problem will persist). From http://www.ibm.com/developerworks/library/j-jsf3/.