Monday, January 29, 2007

JSTL date format

if I have a time in String format, and would like to output by using JSTL;
then this is what to do:

First, parse String to Date type:

<fmt:parseDate value="${someDateString}" pattern="yyyy-MM-dd HH:mm:SS" var="expireDate"></fmt:parseDate>

Second, output it with fmt:formatDate:
<fmt:formatDate value="${expireDate}" pattern="yyyy-MM-dd" />

The specified formatting pattern must use the pattern syntax specified by java.text.SimpleDateFormat.

Examples



The following examples show how date and time patterns are interpreted in
the U.S. locale. The given date and time are 2001-07-04 12:08:56 local time
in the U.S. Pacific Time time zone.












Date and Time Pattern
Result
"yyyy.MM.dd G 'at' HH:mm:ss z"

2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy"
Wed, Jul 4, '01
"h:mm a"
12:08 PM

"hh 'o''clock' a, zzzz"
12 o'clock PM, Pacific Daylight Time
"K:mm a, z"
0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa"
02001.July.04 AD 12:08 PM
"EEE, d MMM yyyy HH:mm:ss Z"
Wed, 4 Jul 2001 12:08:56 -0700
"yyMMddHHmmssZ"

010704120856-0700