Page 1 of 1

How to add date/time to page

Posted: Tue Sep 11, 2007 3:27 pm
by leet8845
Hi,

I'm trying to add the date/time to my CMSMS site.

I have tried some different .js methods, all work fine on my site without CMCMS, but when I try the same method on a my CMSMS site thery don't work.

Can it done with PHP and HTML? Does anyone know a method of acheiving this?

Many Thanks

Lee

Re: How to add date/time to page

Posted: Tue Sep 11, 2007 3:47 pm
by alby
leet8845 wrote: I have tried some different .js methods, all work fine on my site without CMCMS, but when I try the same method on a my CMSMS site thery don't work.
In template you must surround your js with: {literal} ... {/literal}

leet8845 wrote: Can it done with PHP and HTML? Does anyone know a method of acheiving this?
Have you look in plugins section?
There are current_date or (for pages) created_date, recently_updated and last_modified_by

Alby

Re: How to add date/time to page

Posted: Tue Sep 11, 2007 11:18 pm
by leet8845
Thanks Alby,

I have added the {literal} ... {/literal} tags but I think I am doing wrong somehow;

Code: Select all

{literal}<__script__ language="JavaScript" type="text/JavaScript">
function initArray() {
for(i=0;i<initArray.arguments.length; i++)
this[i] = initArray.arguments[i];
}
var isnMonths=new initArray("JANUARY","FEBRUARY","MARCH",
"APRIL","MAY","JUNE",
"JULY","AUGUST","SEPTEMBER",
"OCTOBER","NOVEMBER","DECEMBER");
var isnDays= new initArray("Sun","Mon","Tue","Wed",
"Thu","Fri","Sat","Sun");
today=new Date();
hrs=today.getHours();
min=today.getMinutes();
sec=today.getSeconds();
clckh=""+((hrs>12)?hrs-12:hrs); 
clckm=((min<10)?"0":"")+min;
clck=(hrs>=12)?"PM":"AM";

var stnr="";
var ns="0123456789";
var a="";

function getFullYear(d) { // d is a date object
yr = d.getYear();
if (yr < 1000)
yr+=1900;
return yr;
}
</__script>
<__script__>document.write(" "+isnDays[today.getDay()]+", "+isnMonths[today.getMonth()]+" "+today.getDate()+", "+getFullYear(today)+"");</__script>

<__script__>document.write(" "+clckh+":"+clckm+" "+clck+" ");</__script>{/literal}
Any ideas?

Many Thanks

Lee

Re: How to add date/time to page

Posted: Wed Sep 12, 2007 12:14 am
by calguy1000
smarty has variables built in for the date and time
as well as customcontent

Re: How to add date/time to page

Posted: Wed Sep 12, 2007 2:52 am
by Nullig
I have a UDT that I use called servertime that I call in my footer. It puts a "realtime" clock wherever you place it.

The UDT code:

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 "
<__script__ type=\"text/javascript\">
<!--
function clock() {
    document.write('<span id=\"clock\"></span>');
    var server = new Date($sy, $sm, $sd, $sh, $isi, $iss).getTime();
    var client = new Date().getTime();
    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 = ',Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(/,/g);
    var clock = document.getElementById(\"clock\");
    if(clock) {
        clock.innerHTML='Server Time: '+
            month_names[d.getMonth()]+' '+d.getDate()+', '+d.getFullYear()+' '+
            d.getHours()+':'+i+':'+s;
        setTimeout('tick(' + diff + ');', 1000);
    }
}

clock();
//-->
</__script>";
Then call it in your template like this:

Code: Select all

{servertime}
Nullig

Re: How to add date/time to page

Posted: Wed Sep 12, 2007 3:37 am
by calguy1000
Recomended reading for all users:  http://smarty.php.net/crashcourse.php

the answer to this post is simply {$smarty.now|date_format}

Now if it doesn't display to your liking, then the smarty docs explain exactly how to change the output.

I recommend a 'recommended reading' or a 'have you read this before you post' section be put up somewhere.