I need to show time user connect with Ajax.

For example this is local time

PHP Code:
<?php 
function clock(){
?> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9"> 
<script> 
function show2(){ 
if (!document.all&&!document.getElementById) 
return 
thelement=document.getElementById? document.getElementById("tick2"): document.all.tick2 
var Digital=new Date() 
var hours=Digital.getHours() 
var minutes=Digital.getMinutes() 
var seconds=Digital.getSeconds() 
var dn="" 
if (hours<=9) 
hours="0"+hours 
if (minutes<=9) 
minutes="0"+minutes 
if (seconds<=9) 
seconds="0"+seconds 
var ctime=hours+":"+minutes+":"+seconds+" "+dn 
thelement.innerHTML=""+ctime+"" 
setTimeout("show2()",1000) 

window.onload=show2 
</script> 

<? 

echo 
'<table align= "center"><tr>'
echo 
"<td id=tick2 class=header_down>".clock()."</td>"
echo 
"</tr></table>"
?>
And i need edit to show time from database.

Now my code is (with php)

PHP Code:
function mk_time($s) {
    if (
$s 0)
        
$s 0;
    
$t = array();
    foreach (array(
"60:sec","60:min","24:hour","0:day") as $x) {
        
$y explode(":"$x);
        if (
$y[0] > 1) {
            
$v $s &#37; $y[0];
            
$s floor($s $y[0]);
        }
        else
            
$v $s;
        
$t[$y[1]] = $v;
    }

    if (
$t["day"])
        return 
$t["day"] . "d " sprintf("%02d:%02d:%02d"$t["hour"], $t["min"], $t["sec"]);
    if (
$t["hour"])
        return 
sprintf("%d:%02d:%02d"$t["hour"], $t["min"], $t["sec"]);
//    if ($t["min"])
        
return sprintf("%d:%02d"$t["min"], $t["sec"]);
//    return $t["sec"] . " secs";
}

$timeconnect "<a>" mk_time($row["timeconnect"]) . "</a>"
Now only if i do refresh i can see the real time connect.