views:

909

answers:

1

Hi! In my Web Application I retrieve data using Hibernate and display it in a RichFaces dataTable.

In my MySQL-table there is a field of type "date". When I print this field to the log in my Bean, it shows the correct date from database (e.g. 2010-04-21). But in the rich:dataTable it shows up like this:

4/20/10

So there is a discrepancy of 1 day!

I added the "f:convertDateTime" converter and set the "type" attribute to "both" in order to display time too. So now it shows:

4/20/10 10:00:00 PM

The Code for "f:convertDateTime" I've used:

<f:convertDateTime locale="locale.US" type="both" dateStyle="short"/>

So it seems like f:convertDateTime dreams up some time because there is no time information in the MySQL-table field!

What am I doing wrong? What do I need to do to display the correct date?

Thanks Tom

A: 

You are probably having issues with the Time zones.

Check this article on how to resolve them.

Before that, you can try explicitly setting the timeZone attribute of <f:convertDataTime>

Bozho
I've tried to set the timeZone attribute of <f:convertDateTime> but now the time says 11 PM (because my timezone is GMT+1). It seems like <f:convertDateTime> is defaulting my time to 10PM UTC.
Tom
and did you try the other options?
Bozho
Yes. I've set the Timezone in an ServletContextListener but the result was (of course) the same. The core problem is that <f:convertDateTime> invents time values to my date-value (there is only a date, no time). However the workaround I currently use is to set the timezone to GMT+2, so that the output is 4/21/10 00:00:00 instead of 4/20/10 22:00:00. But thats not an ideal solution :)
Tom
well, if you store date and want to show time there is no way it can be relevant.
Bozho
yep and i just want to see a date(e.g. database field contains 4/22/10)! But <f:convertDateTime display="date"> then shows 4/21/10 (minus one day). So in order to investigate this problem i changed display-attribute to <f:convertDateTime display="both"> and voila <f:convertDateTime> pretends it's 22:00:00 in the evening...and that's the problem
Tom