How do I format a date in a JSP page?

This example show how to format date in JSP using format tag library. We create a date object using the <jsp:useBean> taglib. To format the date we use the <fmt:formatDate> taglib. We assign the value attribute to the date object, set the type attribute as date and define the pattern how the date will be formatted.

<%@ taglib uri="" prefix="fmt" %>
<!DOCTYPE html>
<html lang="en">
    <title>Date Format</title>
<jsp:useBean id="date" class="java.util.Date"/>
Today is: <fmt:formatDate value="${date}" type="date" pattern="dd-MMM-yyyy"/>

Maven Dependencies


Maven Central Maven Central