Display Server Time

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: Display Server Time

Post by Nullig »

Have you changed:

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

in your config.php?


Nullig
Oscar Luijben
Forum Members
Forum Members
Posts: 63
Joined: Tue Nov 28, 2006 9:33 pm

Re: Display Server Time

Post 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>
Last edited by Oscar Luijben on Wed Jul 18, 2007 11:10 am, edited 1 time in total.
taufikp
Forum Members
Forum Members
Posts: 27
Joined: Tue May 01, 2007 2:52 am

Re: Display Server Time

Post 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.
Post Reply

Return to “Tips and Tricks”