JSF page reflects Date incorrectly - 1 Day shifted [duplicate]

安稳与你 提交于 2019-11-30 05:06:08

问题


DB value of Date is:

04-OCT-10

Bean method returns:

Mon Oct 04 00:00:00 EEST 2010

JSF returns:

03.10.2010

JSF code:

...
     <h:outputText value="#{paym.dueDate}" >
            <f:convertDateTime pattern="dd.MM.yyyy"/>
     </h:outputText>
...

What reason(s),that JSF displays Date value incorrectly?

thank you


回答1:


The JSF date converters defaults to UTC timezone. But your date is apparently stored using EEST timezone which is some hours beyond UTC (GMT+3 to be precise). When intepreting those dates using UTC timezone (as JSF by default does), you will get hours back in time and thus the previous day will be represented.

You need to explicitly specify the timezone in <f:convertDateTime>:

<f:convertDateTime pattern="dd.MM.yyyy" timeZone="GMT+3" />



回答2:


Also consider This answer Which might be best suited for countries with different summer/winter time, and when both your server timezone and jsf app user timezone is such a timezone.



来源:https://stackoverflow.com/questions/6244005/jsf-page-reflects-date-incorrectly-1-day-shifted

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!