primefaces calendar: wrong date entry

后端 未结 8 819
心在旅途
心在旅途 2021-02-07 21:49

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 manag

相关标签:
8条回答
  • 2021-02-07 22:29

    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>
    
    0 讨论(0)
  • 2021-02-07 22:29

    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

    0 讨论(0)
  • 2021-02-07 22:31

    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 讨论(0)
  • 2021-02-07 22:31

    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
    
    0 讨论(0)
  • 2021-02-07 22:36

    If you are using primefaces 5, in your scheduler :

    <p:schedule ...ignoreTimezone="false" />
    
    0 讨论(0)
  • 2021-02-07 22:39

    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>
    
    0 讨论(0)
提交回复
热议问题