File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes MyFaces-Date/TimeZone Issue? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "MyFaces-Date/TimeZone Issue?" Watch "MyFaces-Date/TimeZone Issue?" New topic

MyFaces-Date/TimeZone Issue?

Amol Chavan

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"/>

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


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

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.

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

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: 17417

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.

An IDE is no substitute for an Intelligent Developer.
pranjal mishra

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%)
I agree. Here's the link:
subject: MyFaces-Date/TimeZone Issue?
It's not a secret anymore!