javascript - Show a clock on jsp -


i want show clock on jsp file, time fetched server , in 05 jun, 2012 12:48:23 pm format want same time updated rather taking client time.

i did tried hands on timer.js, jtimer , other api's same. can splitting things , writing whole clock logic myself want reuse api has been developed.

i using many years:

<script type="text/javascript">  // current server time script (ssi or php)- javascriptkit.com (http://www.javascriptkit.com) // , on 400+ free scripts, visit javascript kit- http://www.javascriptkit.com/ // notice must stay intact use.  //depending on whether page supports ssi (.shtml) or php (.php), uncomment line below page supports , comment 1 not: //default ssi method uncommented, , php commented:  var currenttime = '<!--#config timefmt="%b %d, %y %h:%m:%s"--><!--#echo var="date_local" -->' //ssi method of getting server date //var currenttime = '<? print date("f d, y h:i:s", time())?>' //php method of getting server date  ///////////stop editting here/////////////////////////////////  var montharray=new array("january","february","march","april","may","june","july","august","september","october","november","december") var serverdate=new date(currenttime)  function padlength(what){ var output=(what.tostring().length==1)? "0"+what : return output }  function displaytime(){ serverdate.setseconds(serverdate.getseconds()+1) var datestring=montharray[serverdate.getmonth()]+" "+padlength(serverdate.getdate())+", "+serverdate.getfullyear() var timestring=padlength(serverdate.gethours())+":"+padlength(serverdate.getminutes())+":"+padlength(serverdate.getseconds()) document.getelementbyid("servertime").innerhtml=datestring+" "+timestring }  window.onload=function(){ setinterval("displaytime()", 1000) }  </script>  <p><b>current server time:</b> <span id="servertime"></span></p>  <p style="font: normal 11px arial">this free script provided by<br /> <a href="http://www.javascriptkit.com">javascript kit</a></p> 

for more informations see this


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -