jQuery in Action, 2nd edition
The moose likes JSF and the fly likes MyFaces-Date/TimeZone Issue? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSF
Reply Bookmark "MyFaces-Date/TimeZone Issue?" Watch "MyFaces-Date/TimeZone Issue?" New topic
Author

MyFaces-Date/TimeZone Issue?

Amol Chavan
Greenhorn

Joined: Sep 04, 2005
Posts: 28
Hi Ranchers,

I am having an issue with date display in an JSF application
say 31/12/2006 date is being displayed as 30/12/2006
while in DataBase it is stil 31/12/2006.
what may be an issue?
is it an issue related to MyFaces?
I got a solution to set Environment variable:
CATALINA_OPTS= -Duser.timezone = GMT while starting server (Tomcat5.0)
but I can ask client to do this each time at the server start-up.
So how to set up this var for Tomcat as well as JBoss because this variable solves the problem.

Mycode snippet:

<t:inputText styleClass="inputdis" id="txtLrs11" value="#{scheduleBean.datScheduleDate11}" readonly="true">
<f:convertDateTime timeZone="#{policyBean.timezone}" pattern="MM/dd/yyyy"/>
</t:inputText>
---------------

in the above code:
policyBean.timezone is to set timezone to "GMT+10)" bcos in MyEclipse I don know how to set CATALINA_OPTS.
its working fine but then while saving it to DataBase it is saving as 30/12/2006 instead of 31/12/2006.

Please Help me.
Thanks in Advance.....


Thanks n Regards,<br />Amol
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
I wrote my own datetime converter to get around this issue



Registered my convertor



Usage:



MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Amol Chavan
Greenhorn

Joined: Sep 04, 2005
Posts: 28
Thanks a lot,
Lynette Dawson
It really helped me and issue is resolved now.

Once again thanks for your help.
Venkat Sadasivam
Ranch Hand

Joined: May 10, 2008
Posts: 139
To resolve the timezone and date pattern issue, an alternative approach can be found here.

http://venkatsadasivam.wordpress.com/2008/07/08/jsf-default-timezone-and-date-pattern/


“Any fool can write code that a computer can understand. Good programmers write code that humans can understand. ”<br>
-Martin Fowler
Bhaskar GR
Greenhorn

Joined: Jun 13, 2008
Posts: 28
<f:convertDateTime type="date" pattern="dd/MM/yyyy"/>
use this tag .I think it will work
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 11706

This is a really irritating property of the JSF datetime converter. It defaults to translating to GMT and the only way to use a local timezone is to either explicitly code the timezone (instead of depending on user locale info) or to use one of the workarounds people have listed above.


A lot the of modern-day software development platforms are designed to permit parcelling out work to those with the best aptitude for it. A lot of modern-day business is predicated on making one person do all the work, regardless of aptitude.
pranjal mishra
Greenhorn

Joined: Jan 08, 2009
Posts: 21
Well I was facing the same issue as Amol had, but I removed the timeZone attribute from the <f:convertDateTime /> tag, and guess what I got it on the track.


SCJP 1.5(95%)
 
 
subject: MyFaces-Date/TimeZone Issue?
 
Two Laptop Bag