Solved

Get system time and date in JSP

Posted on 2008-06-23
3
2,624 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Fine Tune your automatic Updates for Ubuntu / Debian
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now