php - Creating a zone related clock -
i have working clock local server , browser (local system). both works great. want find time offset between clocks, based on seconds, , add local system clock.
for example: system clock is: 10:00:00 , server clock 12:15:00 @ same date. offset be: 02:15:00 (of course in seconds example wrote way). , add (browser)local time show server time. 12:15:00.
this i'm doing here:
var interval = self.setinterval(function(){ clock(); },1000); function clock() { //get local server time <?php $today = getdate(); ?>; var ser = <?php echo $today[0]; ?>; //local client time var seconds = date.now(); var offset = seconds-ser*1000; parseint(offset/1000); var d = new date(); d.settime(date.now()-offset); var h = d.gethours(); var m = d.getminutes(); var s = d.getseconds(); if(s < 10) s = "0" + s; if(m < 10) m = "0" + m; if(h < 10) h = "0" + h; var tm = h+":"+m+":"+s; document.getelementbyid("clock").value = tm; }
but put variable
offset
in line: d.settime(date.now()-offset);
the clock doesn't updates anymore. guess there issue php compatibility. idea how solve it?
the offset calculation has outside of repeadly called function:
//get local server time <?php $today = getdate(); ?>; var ser = <?php echo $today[0]; ?>; //local client time var seconds = date.now(); var offset = seconds-ser*1000; parseint(offset/1000); // way: returnval of parseint isn't stored anywhere, line nothing var interval = self.setinterval(function(){ clock(); },1000); function clock() { var d = new date(); d.settime(date.now()-offset); var h = d.gethours(); var m = d.getminutes(); var s = d.getseconds(); if(s < 10) s = "0" + s; if(m < 10) m = "0" + m; if(h < 10) h = "0" + h; var tm = h+":"+m+":"+s; document.getelementbyid("clock").value = tm; }
Comments
Post a Comment