JSF页面反映日期不正确 - 1天移动 [英] JSF page reflects Date incorrectly - 1 Day shifted

查看:461
本文介绍了JSF页面反映日期不正确 - 1天移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

日期的数据库值为:

  04-OCT-10 

Bean方法返回:

  1月10日04:00 00:00:00 EEST 2010 

JSF返回:

  03.10.2010 

JSF代码:

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

什么原因, JSF 显示日期值不正确?



谢谢

解决方案

JSF日期转换器默认为UTC时区。但是,您的日期显然是使用EEST时区存储的,这个时区超过了UTC(GMT + 3)准确的时间。当使用UTC时区(作为JSF默认情况下)使用这些日期时,您将获得时间,因此前一天将被表示。



您需要明确在< f:convertDateTime> 中指定时区:

  f:convertDateTime pattern =dd.MM.yyyytimeZone =GMT + 3/> 


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

解决方案

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

这篇关于JSF页面反映日期不正确 - 1天移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆