user2254180
user2254180

Reputation: 856

JSP displaying Datetime instead of Date

I have a JSP that is fetching records from an Oracle database. When I preform the SQL query in Oracle, I am getting dates in the format that I expect (i.e. 06-JAN-14).

However, in my JSP, I am using JSTL to query the database and put the records into a JQuery DataTable. Unfortunately, somewhere along in the process, timestamps are being added to the dates, i.e. (2014-01-07 00:00:00.0).

This is my SQL query inside the JSP.

<sql:query var="retrieveMovers" dataSource="jdbc/blahApp">
    SELECT * FROM blah
</sql:query>

This is the table I am outputting results to.

    <table id="movers" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
        <thead>
            <tr>
                <th>Security</th>
                <th>Comment</th>
                <th>Bid Price</th>
                <th>Bid Percent Change</th>
                <th>Security Description</th>
                <th>Date</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach var="row" items="${retrieveMovers.rows}">
                <tr>
                    <td>${row.security}</td>
                    <td>${row.comment}</td>
                    <td>${row.bid_price}</td>
                    <td>${row.bid_percent_change}</td>
                    <td>${row.security_description}</td>
                    <td>${row.date}</td>
                </tr>
            </c:forEach>
        </tbody>
    </table> 

Can anyone make any suggestions how I can ensure my date row doesn't have a time stamp added to it?

Thanks!

Upvotes: 1

Views: 1930

Answers (2)

thiago.lenz
thiago.lenz

Reputation: 409

Try this

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
...
<fmt:formatDate value="${bean.date}" pattern="yyyy-MM-dd" />

Upvotes: 3

JB Nizet
JB Nizet

Reputation: 691755

A Date doesn't have any intrinsic format. What you're seeing is the result of calling toString() on the java.sql.Timestamp instance of the row. You should format the date as you want it:

<fmt:formatDate value="${row.date}" pattern="dd MMM yyyy" />

for example.

Upvotes: 4

Related Questions