• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

f:convertDateTime not working

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shafik,
I used the context-parm approach and it works properly now. Thanks for the solution.

regards,
Nirvan.
 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic