What is JSP Date Handling ?
In this tutorial I have tried to explain a certain criteria on JSP data handling, no doubt this tutorial would take you through Java provided Date class
which is available in java.util package, this class encapsulates the
current date and time. The Date class supports two constructors. The first
constructor initializes the object with the current date and time.
Example:
JSP File (date.jsp)
<%@ page import="java.io.*,java.util.*" %>
<%@ page import="javax.servlet.*,java.text.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Nirajanghimireyworkshop.blogspot.com</title>
</head>
<body>
<center>
<h1>Example for handling date and time </h1>
<h3>Current date and time: </h3>
<%
Date date = new Date();
out.print(date.toString());
%>
<h2> Formatting date </h2>
<h3>Current date and time: </h3>
<%
Date dNow = new Date( );
SimpleDateFormatft =
newSimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
out.print(ft.format(dNow));
%>
</center>
</body>
</html>
No comments:
Post a Comment