2021-01-28

Why does JSF output change date?

I have a SQL Server database where some columns have a datetime type but store only a date with the time parts all being zero.

A Java web app running on WebSphere Portal uses JSF and Hibernate to read the SQL data and output to HTML. Date columns as above are having the date displayed as the previous day. Which component causes this, and how should I fix it?

Implementation details follow.

A column in SQL Server has type datetime, and contains data like 2020-02-01 00:00:00.000.

The Hibernate table definition has this as a key column with type java.sql.Timestamp.

<key-property name="contractBeginDate" column="Contract_Begin" type="java.sql.Timestamp" length="23">
    <meta attribute="field-description">
        @hibernate.property
        column="Contract_Begin"
        length="23"
    </meta>
</key-property>

The Hibernate query to get data is defined as follows.

<query name="getSalesConsultantServiceContractsSold_agreementDate_asc" cacheable="false"><![CDATA[
    FROM VServiceAgreementsList vsal
    WHERE vsal.slmsCode = :slmsCode
    AND vsal.teamEliteYear = :year
    ORDER BY vsal.contractBeginDate ASC
]]></query>

The Java class for the table uses the java.util.Date type for the field and get-method for that column.

Finally, a JSP file with a backing bean produces the HTML output, with the following contained in a column of a dataTable.

<h:outputText id="text8" value="#{varServiceAgreementSalesList.contractBeginDate}" styleClass="outputText">
    <f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>

The data example given above is output as 31/01/2020, one day before the correct date.
I assume a time-zone difference is involved somehow.
All users are in Australia and probably have their PC time-zones set anywhere from UTC+8 to UTC+11, so maybe the original value is being interpreted as the local time-zone, translated to UTC (which will be the previous day), then having the time cut off.



from Recent Questions - Stack Overflow https://ift.tt/3oqg1yg
https://ift.tt/eA8V8J

No comments:

Post a Comment