In JSTL, the role of formatting tag is to specify the type of format that represents date and time. The following syntax represent the URL of formatting tag: –
1 2 3 |
<%@ taglib uri = http://java.sun.com/jsp/jstl/fmt prefix = "fmt" %> |
Formatting tags
These are some commonly used formatting tags: –
- <fmt:parseNumber>: – This tag is used to parse the string on the basis of attribute associate with it.
- <fmt:parseDate>: – This tag is used to parse the string of a date and time.
- <fmt:formatDate>: – This tag handles the date in the various format.
- <fmt:message>: – This tag is used to display the internationalized message.
- <fmt:setTimeZone>: – This tag specifies the type of time zone.
Example of JSTL Format Tag
This is a simple example of JSTL format tag.
index.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<%@ 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>Tutorial and Example</title> </head> <body> <h2>Format Tag example</h2> <c:set var="number" value="99.40" /> <fmt:parseNumber var="n" integerOnly="true" type="number" value="${number}" /> Parse Number is :: <c:out value="${n}" /> <br> <c:set var="date" value="02-04-2018" /> <fmt:parseDate value="${date}" var="pd" pattern="dd-MM-yyyy" /> Parse Date is :: <c:out value="${pd}" /> <br> <c:set var="Date" value="<%=new java.util.Date()%>" /> Format Date is :: <fmt:formatDate type="time" value="${Date}"/> </body> </html> |
Output: