• Post Reply Bookmark Topic Watch Topic
  • New Topic

f:convertDateTime not working  RSS feed

 
B Nirvan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a JSF outputText for which I am using f:convertDateTime to format the output. The problem is that the date gets formatted but its value is set incorrectly. For example, I have a date 26-12-2010 and when I format the date using f:convertDateTime, I get 25-12-2010 instead. I don't know why the formatting takes date 1 day in past. Here is my f:convertDateTime code.


An intresting point to note is that when I format the above date (cityBean.city.dateCreated) in my program and print the formatted date, the date gets formatted correctly. Its only f:convertDateTime in JSF page that is not working properly.

regards,
Nirvan.
 
Hany Shafik
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nirvan,

This has been discussed before in similar posts as it is one of the famous issues in JSF, the problem is in time zone.
By default JSF uses GMT timezone to convert the date into display format, however you can change this behavior is several ways, one is to specify explicitly the timeZone attribute in the f:convertDateTime tag. Two is you can create a custom date converter as suggested in this post date problem. Three if you are using JSF 2 you can apply a global settings for the time zone by adding a context param in the web xml. the context param name is javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE and you can set it to true, this will cause the datetimeconverter to use the default system time zone instead. Hope this can help
 
B Nirvan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shafik,
I used the context-parm approach and it works properly now. Thanks for the solution.

regards,
Nirvan.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!