JSTL Core fmt formatDate Tag
JSTL Core fmt:formatDate Tag
Below is standard syntax to include in your JSP page:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
JSP example:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <h2>fmt:formatDate example</h2> <c:set var="current" value="<%=new java.util.Date()%>" /> <h3>Formatted date with different style</h3> <p>New formatted date: <fmt:formatDate pattern="yyyy-MM-dd" value="${current}" /></p> <p>New formatted date: <fmt:formatDate pattern="MM-dd-yyyy" value="${current}" /></p> <p>New formatted date: <fmt:formatDate pattern="yyyy.MM.dd G 'at' HH:mm:ss z" value="${current}" /></p> <p>New formatted date: <fmt:formatDate pattern="yyyyy.MMMMM.dd GGG hh:mm aaa" value="${current}" /></p> <p>New formatted date: <fmt:formatDate pattern="EEE, d MMM yyyy HH:mm:ss Z" value="${current}" /></p> <h3>Current time</h3> <p>New formatted date: <fmt:formatDate type="time" value="${current}" /></p> <h3>Time with time zone format</h3> <p>New formatted date: <fmt:formatDate type="both" dateStyle="short" timeStyle="short" timeZone="EST+5" value="${current}" /></p> <p>New formatted date: <fmt:formatDate type="both" dateStyle="medium" timeStyle="medium" timeZone="EST+5" value="${current}" /></p> <p>New formatted date: <fmt:formatDate type="both" dateStyle="long" timeStyle="long" timeZone="EST+5" value="${current}" /></p> <h3>Time with type date</h3> <p>New formatted date: <fmt:formatDate type="date" value="${current}" /></p> <p>New formatted date: <fmt:formatDate type="both" value="${current}" /></p> </body> </html>
Output:
Download Project: jstl-1.2