Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSF2的日期格式不同于相同的postgres时间戳列_Jsf_Date_Jsf 2 - Fatal编程技术网

JSF2的日期格式不同于相同的postgres时间戳列

JSF2的日期格式不同于相同的postgres时间戳列,jsf,date,jsf-2,Jsf,Date,Jsf 2,在postgres 9.2中,我有一个带有时间戳的列 CREATE TABLE pilot ( id bigint NOT NULL, birthdate timestamp without time zone NOT NULL, firstname character varying(50) NOT NULL, CONSTRAINT pilot_pkey PRIMARY KEY (id ) ) 我使用Hibernate的java main直接插入了一些行: for (

在postgres 9.2中,我有一个带有时间戳的列

CREATE TABLE pilot
(
  id bigint NOT NULL,
  birthdate timestamp without time zone NOT NULL,
  firstname character varying(50) NOT NULL,
  CONSTRAINT pilot_pkey PRIMARY KEY (id )
)
我使用Hibernate的java main直接插入了一些行:

    for (int i = 0; i < 10; i++) {
        Pilot p = new Pilot();
        p.setBirthdate(new Date());
        p.setFirstname("Johnson_" +tabchar[i] );
        em.persist(p);
    }
JSF2中继到hibernate时会插入一些行: 我正在使用JSF2.1.13

    <h:form id="formPilot">
        <h:panelGrid columns="2">
            <h:outputLabel value="#{appMsg['pilot.firstname']}" />
            <h:inputText id="firstname" label="#{appMsg['pilot.firstname']}" value="#{pilotHolder.pilot.firstname}"
                required="true" />

            <h:outputLabel value="#{appMsg['pilot.birthdate']}" />
            <h:inputText id="birthdate" label="#{appMsg['pilot.birthdate']}" value="#{pilotHolder.pilot.birthdate}"
                required="true">
                <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" timeZone="GMT+1"/>
            </h:inputText>

        </h:panelGrid>
        <h:commandButton id="merge" action="#{pilotAction.doMerge}"
            value="#{pilotHolder.pilot.id ne null ? appMsg['pilot.update'] : appMsg['pilot.create']}" />
    </h:form>   

在数据库中“一切正常”,所有日期都正确(小时数正常)

但是当我显示飞行员列表并在页面上显示Hibernate在没有JSF的情况下插入的日期时,错误减少了1小时, 不是我用JSF插入的时间戳

        <h:column>
            <f:facet name="header">
                <h:outputText value="#{appMsg['pilot.birthdate']}" />
            </f:facet>
            <h:outputText value="#{p.birthdate}" >
               <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" timeZone="GMT+1"/>
            </h:outputText>
        </h:column>

奇怪的是,我在使用DBvisualizer的DB中没有任何区别,它们看起来都很相似, 如果我在Hibernate获取它们之后打印日期,一切都正常

如果我仔细查看Hibernate插入并取回的日期,它们包含一个字段cdate not null,类型为Gregorian$Date。 JSF插入并回传的日期的cdate=null

为什么??
为什么JSF2对它们有不同的解释?

我认为这与夏令时有关

在你的
web.xml中试试这个


javax.faces.DATETIMECONVERTER\默认\时区\是\系统\时区
真的
或者您可以告诉
f:dateTimeConverter
要使用哪个
时区。

只需使用不使用夏令时的
时区

它对我有用。有了这个全局参数javax.faces.DATETIMECONVERTER\u DEFAULT\u TIMEZONE\u IS\u SYSTEM\u TIMEZONE设置为true,JSF不考虑java.util.Date的时区。我仍然不明白两件事:1-为什么postgres用数据库类型保留时区信息:没有时区的时间戳?2-为什么JSF使用timezone=“GMT+1”对带时区和不带时区的日期whrn进行不同的处理?我得再看看。。。
        <h:column>
            <f:facet name="header">
                <h:outputText value="#{appMsg['pilot.birthdate']}" />
            </f:facet>
            <h:outputText value="#{p.birthdate}" >
               <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" timeZone="GMT+1"/>
            </h:outputText>
        </h:column>