Formatting java.sql.Date string in JSP using JSTL formatDate
I am having a problem with JSTL formatDate when displaying dates from MySQL database. I am using a DAO layer to communicate with a database, and in beans, dates are stored in objects java.util.Date
. 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 cannot be obtained, but I don't know how to make it syntactic. I'm not sure if I can use the attribute parseLocale
because this date format is ANSI SQL date format and is not represented by any object Locale
.
How do I fix this with JSTL?
Why are you trying to parse what already appears to be a date object? Is season.startDate a string? If it's a String, you only need to change the syntax format to yyyy-MM-dd HH: mm: ss.z. If it isn't, then are you processing the date instead of formatting it (... by accident)?