JSP date example

Till now you learned about the JSP syntax, now I will show you how to
create a simple dynamic JSP page that prints the current date and time.
So the following code accomplish this:
| <%@page
contentType="text/html" import="java.util.*"
%>
<!--
http://www.roseindia.net/jsp
-->
<html>
<body>
<p> </p>
<div align="center">
<center>
<table border="0"
cellpadding="0"
cellspacing
="0"
width="460"
bgcolor="#EEFFCA">
<tr>
<td width="100%"><font
size="6"
color
="#008000"> Date
Example</font></td>
</tr>
<tr>
<td width="100%"><b> Current
Date
and time is: <font
color="#FF0000">
<%=
new java.util.Date() %>
</font></b></td>
</tr>
</table>
</center>
</div>
</body>
</html>
|
The heart of this example is Date() function of the java.util
package which returns the current data and time.
In the JSP Declaratives
<%@page contentType="text/html"
import="java.util.*" %>
we are importing the java.util package and
following JSP Expression code
<%= new
java.util.Date() %>
prints the current date on the page.
Execute the example.
Download the code

|
Current Comments
16 comments so far (post your own) View All Comments Latest 10 Comments:i have one form, in that i have two text box which is used to get only hours and minutes like starting and ending time s of classes(9:30 to 10:30)
after receiving that value from the form i want store it in oracle table...
by using condition i want to retrive the record set deatils which is equal to 9:30 to 10:30.....
Posted by vasanthi on Monday, 03.24.08 @ 18:02pm | #54161
i want to retrieve date fields from the database in jsp with some user condition ie
i get input from_date and to_date from the user , then i want to retrieve the records present in my database with that given dates.
plz...../
Posted by pavithra on Wednesday, 02.27.08 @ 21:01pm | #50324
how can i create a web project using jsp in myeclipse........please inform me
Posted by Ramanuja Reddy on Saturday, 02.2.08 @ 10:59am | #46950
i am really thanks this web site
this one of the devlober best site very nice roseindia.net
Posted by prakasam on Friday, 01.25.08 @ 12:34pm | #46106
Your web site is absolutely marvelous....... it has got most of the fundamentals right and its very informative....... im a employee of Ness Technologies, Banglore n am a very good reader of the articles in ur web......
Thank u......
Regards,
Abdullah khan
Posted by Abdullah khan on Tuesday, 10.23.07 @ 09:39am | #34601
I want to get the time only.
How i want to write the program.
This program show all date month year time
Posted by selestin on Tuesday, 10.16.07 @ 14:56pm | #34197
if any body ask the exact definition of web server then wat to answer can any body tell me??????/
Posted by neha on Monday, 09.17.07 @ 16:03pm | #27118
hi while compliling the same date.jsp ,im getting error for generated servlet saying that cannot access the java.lang.object bad class file with (JRE path)
along with version saying that actual version is 48.0 and file is 49.0 either select the correct subdirectory or path .
please provide me solution .
Posted by mukesh on Monday, 08.27.07 @ 11:33am | #24236
helo sri
Before compiling u must have installed apache tomcat webserver& u need to set environment variablesas follows
JAVA_HOME
(j2sdk installed folder)(i.e c:\j2sdk1.4)
CATALINA_HOME
(TOMCAT INSTALLED FOLDER)
CLASSPATH
(C:\J2SDK1.4\BIN)
select path from exising and edit it and paste the classpaths VALUE I.E C:\J2SDK1.4\BIN;
SEMICOLON IS NESSESARY IN STARTING& ENDING
----------------------------------------
NOW SAVE YOUR PROGRAM IN TOMCAT FOLDER UNDER WEBAPPS & RUN THE SERVER AND DEPLOY YOUR PROGRAM
ALL THE BEST!
Posted by reddikishsore on Wednesday, 08.22.07 @ 20:08pm | #23924
hi,
Can u please let me know how i can compile my jsp that is saved as "abc.jsp" in my system on desktop.
Regards,
sri
Posted by srinivasan on Thursday, 08.9.07 @ 13:16pm | #23004