f:如果时区由bean提供,则convertDateTime显示错误日期

虽然将时区指定为字符串文字是完美的:

<h:outputText value="#{item.dateChange}">
    <f:convertDateTime pattern="dd.MM.yyyy HH:mm" timeZone="Europe/Berlin"/>
</h:outputText>

按bean提供值不起作用(Timeoffset 1h到UTC和夏令时1h不适用)

<h:outputText value="#{item.dateChange}">
    <f:convertDateTime pattern="dd.MM.yyyy HH:mm" timeZone="#{item.platform.timeZone}"/>
</h:outputText>

我尝试了以下两种方法,但都没有工作:

public TimeZone getTimeZone() {
    return TimeZone.getTimeZone("Europe/Berlin");
}

public String getTimeZone() {
    return "Europe/Berlin";
}

我需要为用户配置时区,这如何实现?

编辑:为了确保时区对象可用:

 <h:outputText value="#{item.platform.timeZone}"/> 

sun.util.calendar.ZoneInfo [ID = “欧洲/柏林”,偏移量= 360万,dstSavings = 3600000,useDaylight =真,过渡= 143,lastRule = java.util.SimpleTimeZone中[ID =欧洲/柏林,偏移= 3600000, dstSavings = 3600000,useDaylight =真,startYear = 0,STARTMODE = 2,startMonth = 2,朝九特派= -1,startDayOfWeek = 1,开始时间= 3600000,startTimeMode = 2,endMode = 2,endMonth = 9,endday指定= -1,一个endDayOfWeek = 1,结束时间= 3600000,endTimeMode = 2]]

或简单地说:“欧洲/柏林”在第二次尝试。


正如Gimby所指出的,一个类似的问题已经由BalusC回答

由于f:标签的限制,一个customConverter是必需的。

有关该问题的详细说明以及BalsuC的示例实现,请点击此处:JSF convertDateTime with datatable中的timezone

注意:在那里提供的转换器期望bean返回一个描述timeZone而不是TimeZone对象的字符串。

链接地址: http://www.djcxy.com/p/3103.html

上一篇: f:convertDateTime displays wrong Date if timezone is provided by a bean

下一篇: Memory leak on GregorianCalendar