1

We have following code on the jsp page

<fmt:formatDate value="${object.mydate}" pattern="yyyy-MM-dd HH:mm:ss" var="mydate" />
<c:out value="${mydate}"/>

My entity

    @Temporal(TemporalType.DATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "DATEEXAMPLE", length = 7)
    public Date getDateExample() {
        return this.dateexample;
    }

in Oracle Database field DATAEXAMPLE is DATA_TYPE "DATE" (and example entry, 14/08/21 17:01:20)

Unfortunately, website displays me "2014-08-21 00:00:00"

Somone know why?

I'am using Oracle Database 11g, Spring 3.2, Hibernate 4.

user2363971
  • 191
  • 1
  • 4
  • 19

2 Answers2

2

The format operations (fmt:formatDate and fmt:formatNumber) default to using .toString() if locale is NULL, even if an explicit format has no conversions that are locale dependent. Depending on the setup of your appserver there may be no default locale, leaving it NULL

Try adding locale

<fmt:formatDate value="${object.mydate}" pattern="yyyy-MM-dd HH:mm:ss" var="mydate" locale="en"/>
<c:out value="${mydate}"/>
Ankur Singhal
  • 26,012
  • 16
  • 82
  • 116
1

Your problem is here:

@Temporal(TemporalType.DATE)

As per the javadoc, this maps to java.sql.Date. And guess what, it holds only the "date" part of the timestamp, not the "time" part. You need the other one, mapping to java.sql.Timestamp.

@Temporal(TemporalType.TIMESTAMP)

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555