Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get system time and date in JSP

Posted on 2008-06-23
3
Medium Priority
?
3,182 Views
Last Modified: 2008-06-24
How to I get system time and date in jsp???
0
Comment
Question by:KenTan85
  • 2
3 Comments
 
LVL 3

Expert Comment

by:ofkr
ID: 21844362
<%@ page import="java.text.*,java.util.*" session="false"%>
<%!
   DateFormat fmt = new SimpleDateFormat("hh:mm:ss aa");
   String currenttime = fmt.format(new Date());
%>
current time is <%= currenttime %>
0
 

Author Comment

by:KenTan85
ID: 21844611
DateFormat cannot be resolved to a Type

I am having this error
0
 
LVL 3

Accepted Solution

by:
ofkr earned 2000 total points
ID: 21844762
Here is the complete code tested in NetBeans - Pls test out with complete code.


<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="java.text.*,java.util.*" session="false"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
--%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
 
<%
   DateFormat fmt = new SimpleDateFormat("hh:mm:ss aa");
   String currenttime = fmt.format(new Date());
%>
 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
    current time is <%= currenttime %>
 
    </body>
</html>

Open in new window

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Your business may be under attack from a silent enemy that is hard to detect. It works stealthily in the shadows to access and exploit your critical business information, sensitive confidential data and intellectual property, for commercial gain. T…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question