Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

f:convertDateTime doesn' modify the displayed date  RSS feed

 
Franc Crosses
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bean with a field "lastUpdate", which is of type Date, and its usual getter/setter.
I use JPA to persist my beans into a PostGreSql DB.

I want to have my lastUpdate be saved in UTC, so before setting it, I set the time zone:


So, if lastUpdate is "2013-08-02 12:17:05" (Europe/Zurich), in the DB I have "2013-08-02 10:17:05" (UTC), which is what I want.

When I display the date back, I also want to have it according to my time zone, so I thought I could use the f:convertDateTime and setting the timeZone="xxx".



Reading other answers, I tried to set the

javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE

too, but the result is always the same: by displaying the date I get 2013-08-02 10:17:05 instead 2013-08-02 12:17:05.

I think that if the converter does its job correctly, if I want to display 2013-08-02 10:17:05 (UTC) according my time zone, setting the time zone to mine (Europe/Zurich), I should get 2013-08-02 12:17:05

Do I miss something??

In the DB, the column is of type "timestamp without time zone". Does it have some effect?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A much simpler way to get the current time in UTC is this:



The epoch for the java.util.Date object is midnight January 1, 1970 UTC. So you do not need Calendar here.

I think you are also hurting yourself by attempting to override JSF's TIMEZONE settings, since you are UTC-based. By default, JSF will be working in UTC.
 
Franc Crosses
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the DB, the column is of type "timestamp without time zone".

This is the problem. If no time zone is specified, how can the converter know how to adjust the time?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a time is constructed for the UTC (Greenwich) zone and stored without a timezone qualifier, it can be assumed that the (implied) timezone for that timestamp is UTC.

Since JSF defaults to UTC in its date/time conversions, there's nothing more necessary.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!