Page 2 of 2

Re: Display Server Time

Posted: Mon Jul 02, 2007 5:44 pm
by Nullig
Have you changed:

$config['use_smarty_php_tags'] = true; <-- must be true

in your config.php?


Nullig

Re: Display Server Time

Posted: Wed Jul 18, 2007 10:29 am
by Oscar Luijben
I do not want the PM or AM into my clock just a nice 24 hour clock.

Code: Select all

<__script__ type="text/javascript">
<!--
function clock() {
    document.write('<span id="lclock"></span>');
    // here's the PHP code that spawn out the server local time
    <?php list($sy,$sm,$sd,$sh,$si,$ss) = explode(",", date("Y,n,j,G,i,s")); 
    ?>
    // now we represent the server time as javascript date
    var server = new Date(<?=$sy?>, <?=$sm?>, <?=$sd?>, <?=$sh?>, <?=intval($si)?>, <?=intval($ss)?>).getTime();
    // calculate the client time
    var client = new Date().getTime();
    // run our ticker
    tick(client-server);
}
function tick(diff) {
    var d = new Date(new Date().getTime()-diff);
    var i = d.getMinutes(); if(i < 10) i='0'+i;
    var s = d.getSeconds(); if(s < 10) s='0'+s;
    var lclock = document.getElementById("lclock");
    if(lclock) {
        lclock.innerHTML='De lokale tijd is '+
            d.getHours()+':'+i+':'+s+' <?=$sa?>';
        setTimeout('tick(' + diff + ');', 1000);
    }
}
//-->
</__script>

Re: Display Server Time

Posted: Mon Jul 30, 2007 4:16 am
by taufikp
I've made another server's clock snippet, but using User Defined Tags instead.

Create a new UDT, let's name it 'show_clock', then enter the code below:

Code: Select all

list($sy,$sm,$sd,$sh,$si,$ss) = explode(",", date("Y,n,j,G,i,s"));
$isi = intval($si);
$iss = intval($ss);
$host = $_SERVER['HTTP_HOST'];
echo <<< JSClock
<__script__ type="text/javascript">
<!--
function clock() {
    document.write('<span id="clock"></span>');
    // here's the PHP code that spawn out the server local time
    // now we represent the server time as javascript date
    var server = new Date($sy, $sm, $sd, $sh, $isi, $iss).getTime();
    // calculate the client time
    var client = new Date().getTime();
    // run our ticker
    tick(client-server);
}
function tick(diff) {
    var d = new Date(new Date().getTime()-diff);
    var i = d.getMinutes(); if(i < 10) i='0'+i;
    var s = d.getSeconds(); if(s < 10) s='0'+s;
    var month_names = ',Januari,Februari,Maret,April,Mei,Juni,Juli,Agustus,September,Oktober,November,Desember'.split(/,/g);
    var clock = document.getElementById("clock");
    if(clock) {
        clock.innerHTML='Server: $host Time: '+
            d.getDate()+'/'+month_names[d.getMonth()]+'/'+d.getFullYear()+' '+
            d.getHours()+':'+i+':'+s;
        setTimeout('tick(' + diff + ');', 1000);
    }
}

clock();
//-->
</__script>
JSClock;
Now, to use it, just put {show_clock} tag in your page/template.