Nemanja Nedic
Nemanja Nedic

Reputation: 43

Formatting java.sql.Date string in JSP using JSTL formatDate

I'm having a problem with JSTL formatDate when displaying dates from MySQL database. I am using DAO layer for communication with database and in beans, dates are stored in java.util.Date objects. In JSP the code looks like this:

<fmt:parseDate value="${season.startDate}" pattern="dd.MM.yyyy."/>

When I try to run this page I get java.text.ParseException: Unparseable date: "2009-09-01 00:00:00.0".I understand why this is unparseable but I don't know how to make it parseable. I am not sure if I can use parseLocale attribute because this date format is ANSI SQL date format and it is not represented by any Locale object.

How to fix this using JSTL?

Upvotes: 2

Views: 2939

Answers (1)

Alex Marshall
Alex Marshall

Reputation: 10312

Why are you trying to parse what already appears to be a date object ? Is season.startDate a String ? If it is a String, you need only change your parse format to yyyy-MM-dd HH:mm:ss.z. If it's not, then are you parsing the date instead of formatting it (...by accident) ?

Upvotes: 1

Related Questions