12

Using jsf 2.2.0.

For all the date, it seems to remove one day. When I click on 8 nov, it displays 11/08/2011. But then it stores Nov 7, 2011 in my Date field in my managed bean.

I live in singapore, wondering if it's an issue with the timezone.

Mat
  • 202,337
  • 40
  • 393
  • 406
Foo
  • 143
  • 1
  • 2
  • 6
  • 1
    Could be. If not, it can be a problem of Primefaces. It is quite buggy... Anyway, don't use `Date`-s, use `Calendar`-s instead. – zeller Nov 06 '11 at 09:51
  • A Date field can't even store a specific date. All it stores is an integer. There are different ways of transating that integer to a date, which is where your problem is coming from. – MatsT Nov 07 '11 at 14:14
  • @zeller I am interested in your recommendation not to use java.util.Date. Why is this? – 8bitjunkie Oct 25 '13 at 14:59
  • 1
    @7SpecialGems: see this post: http://stackoverflow.com/questions/1404210/java-date-vs-calendar – zeller Oct 26 '13 at 07:22

8 Answers8

25

try adding this to your web.xml

<context-param>
    <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
    <param-value>true</param-value>
</context-param>
Daniel
  • 36,833
  • 10
  • 119
  • 200
  • Its definitely a timezone issue. You may (should be) running your server in UTC. Primefaces will regionalize your date and convert it to the user time. You can, and probably should, run your server with "-Duser.timezone=UTC". The context param should fix it. – Daniel B. Chapman Nov 07 '11 at 16:52
  • Confirmed, timezone issue. The context param fixed it (JSF 2.2.5, PrimeFaces 4.0). – Gilberto Mar 17 '14 at 12:39
2

If you are using primefaces 5, in your scheduler :

<p:schedule ...ignoreTimezone="false" />
0

Adding the argument -Duser.timezone=UTC to the startup parameters fixed problem for me.

To summarize: p:schedule work only well when following parameters are sets:

-Duser.timezone=UTC

<context-param>
    <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
    <param-value>true</param-value>
</context-param>
Miguel
  • 1,966
  • 2
  • 18
  • 32
0

I have just added the following parameter in web.xml and the issue is fixed. I didn't include any command like -Duser.timezone=UTC while starting the server, still its fixed the issue.

javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE true

Regards Khaleel

0

I'm using Wildfly 8 and PF 5.0.RC1 and the only thing that did the trick for me was setting the Timezone of the calendar to nothing...

<p:calendar timeZone = "" />

Don't know if this is a proper solution, seems more like a workaround, but it worked fine locally and deployed.

mradzinski
  • 614
  • 1
  • 8
  • 21
0

Maybe it is because you didn't insert the hours. For example in this case

<p:calendar id="dateFromCalendar"
    value="#{platform.frameBean.dateFrom}" showOn="button"
    pattern="dd-MM-yyyy" timeZone="Europe/Warsaw">
</p:calendar>

the hour will come as 00:00 of the actual day. And because the timezone (-02:00), the hour will appear as 22:00 of the day before the actual day. The correct thing to do is

<p:calendar id="dateFromCalendar"
    value="#{platform.frameBean.dateFrom}" showOn="button"
    pattern="dd-MM-yyyy HH:mm" timeZone="Europe/Warsaw">
</p:calendar>

The hour will appear, so the timezone will make the correct calculations

Ricardo Anjos
  • 1,417
  • 18
  • 22
0

In your calendar component, add a converter and indicate your timezone e.g

<p:calendar id="date">
  <f:convertDateTime timeZone="Asia/Singapore"></f:convertDateTime>
</p:calendar
-1

Have you tried to set the timezone and locate attribute? Otherwise, you can create a converter object that converts the date. This is a tutorial to create a custom converter: http://www.roseindia.net/jsf/customconverter.shtml