Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Server Time on webpages 1

Status
Not open for further replies.

webmast

Programmer
Dec 21, 2001
57
IN
hi,
please help me out..

I want to display the server time on all webpages throught the application.Server side scripting is done using JSP.How to display server time using JSP?..

pri..

 
<%
Date now = new Date();

// Get format as short time: 12:32pm
DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
String time = df.format(now);
%>
The time is: <%= time%>

Note that you can check out the DateFormat API and customize the format so that it displays the date or the timezone info as well.

Regards,

Charles
 
Thanx a lot charles .. i could get the time displayed on the webpage. Is there anyway to continuously refresh the time being displayed so that it looks like a live clock. I would really appreciate any help on that.Thanx once more.

Pri...
 
Hmmm, that is a tough one. Javascript only executes in response to events so it isn't going to give you a continual display. You'd probably have to go with an applet to do a contiuous output. You could add a meta tag to refresh the page every second or so but that would probably bug the heck out of the user.
 
how about write the server's time to the client like charles said, and create a javascript Date object, serverTime, with it; but use the client's time to count seconds and such by using the javascript setTimeout method to increment serverTime. However you want to display it is up to you (in a div tag would be my choice, since it is easily refreshable) ray
rheindl@bju.edu

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top