Solved

Get system time and date in JSP

Posted on 2008-06-23
3
2,570 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
Comment Utility
<%@ 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
Comment Utility
DateFormat cannot be resolved to a Type

I am having this error
0
 
LVL 3

Accepted Solution

by:
ofkr earned 500 total points
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
report generation frameworks 1 58
AlarmClock Challenge 35 145
struts spring hibernate example 12 84
java operators 3 88
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

14 Experts available now in Live!

Get 1:1 Help Now