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?..
// 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.
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.
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.