To print a Date in JSP firstly we are importing a class named java.util.Date of the package java.util. This package is imported in the jsp page so that the Date class and its properties can accessed in the JSP page. To import a package we need to use page directive inside which we will use its one of its attributes named import which is used for importing the class and package.
To print the current date we are using a expression directive in which we are creating a object of Date class. We have used toString() method to convert Date type to String.
The output of the program is given below:
<%@ page import ="java.util.Date" %>
<html>
<head>
<title>The current date is</title>
</head>
<body>
<font size = 6 color = "#FF0000">current date is
:<%= new Date().toString()%></font>
</body>
</html>
|
The output of the program is given below:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Date in JSP View All Comments
Post your Comment