我使用 JSF1.2,但时区有点问题.
I use JSF1.2 and I have a little problem with time zones.
日历尊重我的时区并在数据库中保存正确的时间.当我使用带有 f:convertDateTime 的 h:outputtext 显示它时,它显示了错误的日期(我认为使用默认时区).
Calendar respects my timezone and save the correct time in the Database. When I show it using a h:outputtext with a f:convertDateTime it shows the wrong date (I think with default time zone).
我可以这样做:
<h:outputText value="#{atividade.atividade.dataCriacao.time}"> <f:convertDateTime pattern="#{msg.formatoDataCalendario2}" timeZone="America/Sao_Paulo" /> </h:outputText>formatoDataCalendario2 = dd/MM/yyyy, HH:mm in messages.properties.
formatoDataCalendario2 = dd/MM/yyyy, HH:mm in messages.properties.
我也可以将时区放在消息中,但我相信它有一些我可以使用的配置.
I can put the time zone in messages too, but I believe it have some configuration that I could use.
推荐答案JSF 日期/时间转换器默认为 UTC 时区.如果您想使用不同的时区,那么您确实需要自己在转换器中指定它.或者,如果您对生产运行时环境有 100% 的控制权,那么从 JSF 2.0 开始,您可以将其系统时区设置为所需的时区,并将以下上下文参数添加到 web.xml:
JSF date/time converters defaults by specification to UTC timezone. If you want to use a different timezone, then you really need to specify it in the converter yourself. Or, if you have 100% control over the production runtime environment, then since JSF 2.0 you can set its system timezone to the desired timezone and add the following context parameter to web.xml:
<context-param> <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name> <param-value>true</param-value> </context-param>这样 JSF 将使用由 TimeZone#getDefault() 作为转换器的默认时区.
This way JSF will use the system's timezone as obtained by TimeZone#getDefault() as converter's default timezone.
请注意,java.util.Date 对象本身也不存储任何时区信息.它也始终默认为 UTC 时区.在处理提交的日期/时间时请记住这一点.
Please note that the java.util.Date object by itself also does not store any timezone information. It also always defaults to UTC timezone. Keep this in mind when processing submitted date/times.
- 夏令时和时区最佳做法
更多推荐
为 f:convertDateTime 设置默认时区
发布评论