my question client time displayed, want display server time every seconds.
function getcount(ddate,iid){ var date = new date(); datenow = date; // if time past if(amount < 0){ } // else date still else{ days=0;hours=0;mins=0;secs=0;out=""; amount = math.floor(amount/1000);//kill "milliseconds" secs days=math.floor(amount/86400);//days amount=amount%86400; hours=math.floor(amount/3600);//hours amount=amount%3600; mins=math.floor(amount/60);//minutes amount=amount%60; secs=math.floor(amount);//seconds document.getelementbyid(iid).innerhtml=days; document.getelementbyid('countbox1').innerhtml=hours; document.getelementbyid('countbox2').innerhtml=mins; document.getelementbyid('countbox3').innerhtml=secs; settimeout(function(){getcount(ddate,iid)}, 1000); } }
if want avoid network traffic checking time server every second just: (1) have server pass time in way store in js variable on page load; (2) store client time @ page load; (3) use setinterval update time (every 1000 milliseconds or want) getting current client time minus client time @ page load offset of server time @ page load. (obviously go wrong if user updates pc clock while page running, how many users that? , end of world if did?)
if want actual server time every second - why? seems bit of waste of bandwidth little if benefit, if must use ajax suggested. if you're not familiar ajax i'd suggest using google find tutorials - if use jquery can couple of lines of code. easy.
or put onscreen clock in iframe repeatedly reloads itself. because miss days of iframes.
Comments
Post a Comment