Attributes of the tag <fmt:formatDate>
|
Example:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <title>JSTL fmt:dateNumber Tag</title> </head> <body> <h3>Number Format:</h3> <c:set var="date" value="<%=new java.util.Date()%>" /> <table bgcolor="#D8D8D8" border="1" width="70%"> <tr> <td width="100%" colspan="2" bgcolor="#1C1C1C"> <p align="center"><b> <font color="#D8D8D8" size="4">Formatting: <fmt:formatDate value="${date}" type="both" timeStyle="long" dateStyle="long" /> </font> </b></p> </td> </tr> <tr> <td width="51%">Attribute : type="date"</td> <td width="49%"><fmt:formatDate type="date" value="${date}" /></td> </tr> <tr> <td width="51%">Attribute : type="time"</td> <td width="49%"><fmt:formatDate type="time" value="${date}" /></td> </tr> <tr> <td width="51%">Attribute : type="both"</td> <td width="49%"><fmt:formatDate type="both" value="${date}" /></td> </tr> <tr> <td width="51%">Attribute : type="both" dateStyle="default" timeStyle="default"</td> <td width="49%"><fmt:formatDate type="both" dateStyle="default" timeStyle="default" value="${date}" /></td> </tr> <tr> <td width="51%">Attribute : type="short" dateStyle="default" timeStyle="short"</td> <td width="49%"><fmt:formatDate type="both" dateStyle="short" timeStyle="short" value="${date}" /></td> </tr> <tr> <td width="51%">Attribute : type="both" dateStyle="medium" timeStyle="medium"</td> <td width="49%"><fmt:formatDate type="both" dateStyle="medium" timeStyle="medium" value="${date}" /></td> </tr> <tr> <td width="51%">Attribute : type="both" dateStyle="long" timeStyle="long"</td> <td width="49%"><fmt:formatDate type="both" dateStyle="long" timeStyle="long" value="${date}" /></td> </tr> <tr> <td width="51%">Attribute : type="both" dateStyle="full" timeStyle="full"</td> <td width="49%"><fmt:formatDate type="both" dateStyle="full" timeStyle="full" value="${date}" /></td> </tr> <tr> <td width="51%">Attribute : pattern="yyyy-MM-dd"</td> <td width="49%"><fmt:formatDate pattern="yyyy-MM-dd" value="${date}" /> </td> </tr> <tr> <td width="51%">Attribute : pattern="yyyy-MM-dd hh:mm:ss"</td> <td width="49%"><fmt:formatDate pattern="yyyy-MM-dd hh:mm:ss" value="${date}" /></td> </tr> </table> </body> </html>
This would produce following result:
<fmt:parseDate> Tag–
The <fmt:parseDate> tag is used to parse dates.
Example-
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <title>JSTL fmt:parseDate Tag</title> </head> <body> <h3>Date Parsing:</h3> <c:set var="now" value="20-10-2013" /> <fmt:parseDate value="${now}" var="parsedEmpDate" pattern="dd-MM-yyyy" /> <p>Parsed Date: <c:out value="${parsedEmpDate}" /></p> </body> </html>
This would produce following result: