You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Andrea Grittini <an...@Cdesign.it> on 2002/04/03 13:59:25 UTC

date format

Hello,
Which is the input format in the dateFormat tag of JSTL.??
I'm trying to format a date in long format like MONDAY 10 JULY 2001 using the fmt tag library.
I read the date field from a SQLserver DB, and I always got an Invalid date. (The same if I use the datetime tag library)
 
<fmt:formatDate  pattern="EEEE d MMMM yyyy"><c:out value="${day}"/></fmt:formatDate  >.
 
So I thought that the date coming from db is invalid and I put a parseDate inside:
<fmt:formatDate  pattern="EEEE d MMMM yyyy"> <fmt:parseDate pattern="yyyyMMdd">1999/07/01</fmt:parseDate> </fmt:formatDate>
 
and I got the same error Unparsable date.
Please help me.
 

  
Andrea Grittini ( < mailto:Andrea.Grittini@cdesign.it>)
Tel: +39-2-97482.1- Fax: +39-2-97482?
Computer Design S.r.l., Via Piave 46 - 20010 S.Stefano Ticino - ITALY
< http://www.cdesign.it/> 
  

 

Re: date format

Posted by Shawn Bayern <ba...@essentially.net>.
On Wed, 3 Apr 2002, Andrea Grittini wrote:

> Hello,
> Which is the input format in the dateFormat tag of JSTL.??

By default, it's the "current" locale's representation of the date.  The
"current" locale is determined through a somewhat complex algorithm that's
described well in the spec.

> I'm trying to format a date in long format like MONDAY 10 JULY 2001
> using the fmt tag library. I read the date field from a SQLserver DB,
> and I always got an Invalid date. (The same if I use the datetime tag
> library)
>
>  <fmt:formatDate pattern="EEEE d MMMM yyyy"><c:out
> value="${day}"/></fmt:formatDate >.
>
>  So I thought that the date coming from db is invalid and I put a
> parseDate inside: 
> 
< fmt:formatDate pattern="EEEE d MMMM yyyy">
> <fmt:parseDate pattern="yyyyMMdd">1999/07/01</fmt:parseDate>
> </fmt:formatDate>
>  
> and I got the same error Unparsable date.
> Please help me.

On first glance, it looks like there are two problems:  first, for
<fmt:parseDate>, the pattern doesn't match; try "yyyy/MM/dd" instead.  
Then, once the inner tag works, it will output the default String
representation of a Date.  This may not be parsable using your default
locale; it probably won't be.  Instead, write this:

 <fmt:parseDate var="date" pattern="yyyy/MM/dd">1999/07/01</fmt:parseDate>
 <fmt:formatDate pattern="EEEE d MMMM yyyy" value="${date}"/>

This is currently the best way to string a <fmt:parseDate> tag and a
<fmt:formatDate> tag together.  Given that your initial usage make logical
sense to me, I'm going to ask for debate in the EG about whether it would
be better for <fmt:parseDate> to use the default locale instead of
Date.toString().

-- 
Shawn Bayern
Author, "JSP Standard Tag Library"  http://www.jstlbook.com
(coming this summer from Manning Publications)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>