How to Show Current Date in JSP Page

Show Current Date in JSP Page

In this example, We will show sample program about, How to show current date in JSP page. This example has been tested with apache tomcat server environment and output has been shared in the same post.

Example Program

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.Date"%>
<%@ 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Today Date</title>
</head>
<body>

	
	<%! 
	
		// defining the variable
		Date currentDate;
		String formattedDate;
	
	%>
	
	<%
	
		// creating the date object
		currentDate = new Date();
	
		// creating the dateformet object
		DateFormat df = new SimpleDateFormat("EE, MMMM dd, YYYY");
		
		// formatting the date (ie: Thu, March 05, 2015)
		formattedDate = df.format(currentDate);
	
	%>

	<h1>Hello, Today`s Date is : <%=formattedDate %></h1>

</body>
</html>

Output

How to Show Current Date in JSP Page

References

1. Getting Current Date using Java

Hello everyone, I am a Founder of dineshkrish.com.