...

View Full Version : Need help with dynamic clock script - remove the date but leave the time



ErikaT
10-03-2003, 09:17 PM
Can someone help modify this? I want only the time (with the seconds) to display. Not the date. Also, how can I make the time bold? Thanks

<script language="JavaScript">
function tS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinute s(),tN().getUTCSeconds()); x.setTime(x.getTime()+dS()-21600000); return x; }
function tN(){ return new Date(); }
function dS(){ return ((tN().getTime()>fD(0,3,1,1).getTime())&&(tN().getTime()<fD(0,9,1,-1).getTime()))?3600000:0; }
function fD(d,m,h,p){ var week=(p<0)?7*(p+1):7*(p-1),nm=(p<0)?m+1:m,x=new Date(tN().getUTCFullYear(),nm,1,h,0,0),dOff=0; if(p<0){ x.setTime(x.getTime()-86400000); } if(x.getDay()!=d){ dOff=(x.getDay()<d)?(d-x.getDay()):0-(x.getDay()-d); if(p<0&&dOff>0){ week-=7; } if(p>0&&dOff<0){ week+=7; } x.setTime(x.getTime()+((dOff+week)*86400000)); } return x; }
function lZ(x){ return (x>9)?x:'0'+x; }
function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; }
function y2(x){ x=(x<500)?x+1900:x; return String(x).substring(2,4) }
function dT(){ if(fr==0){ fr=1; document.write('<span id="tP">'+eval(oT)+'</span>'); } tP.innerText=eval(oT); setTimeout('dT()',1000); }
function aP(x){ return (x>11)?'pm':'am'; }
var dN=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'),fr=0,oT="dN[tS().getDay()]+' '+tS().getDate()+'-'+(tS().getMonth()+1)+'-'+y2(tS().getYear())+' '+':'+':'+' '+tH(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '+aP(tS().getHours())";
</script>

-----

<script language="JavaScript">dT();</script>

Kor
10-04-2003, 11:11 AM
modify (get rid of you don't need) here:



oT="dN[tS().getDay()]+' '+tS().getDate()+'-'+(tS().getMonth()+1)+'-'+y2(tS().getYear())+' '+':'+':'+' '+tH(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '+aP(tS().getHours())";


insert <strong></strong> tags here:


document.write('<span id="tP">'+eval(oT)+'</span>');


I assumed that you know enough javascript to do it by yourself
:thumbsup:

ErikaT
10-04-2003, 01:57 PM
I know enough to get me in trouble. :)

I've modified it to this and it seems to be working fine.

<script language="JavaScript">
function tS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinute s(),tN().getUTCSeconds()); x.setTime(x.getTime()+dS()-21600000); return x; }
function tN(){ return new Date(); }
function dS(){ return ((tN().getTime()>fD(0,3,1,1).getTime())&&(tN().getTime()<fD(0,9,1,-1).getTime()))?3600000:0; }
function fD(d,m,h,p){ var week=(p<0)?7*(p+1):7*(p-1),nm=(p<0)?m+1:m,x=new Date(tN().getUTCFullYear(),nm,1,h,0,0),dOff=0; if(p<0){ x.setTime(x.getTime()-86400000); } if(x.getDay()!=d){ dOff=(x.getDay()<d)?(d-x.getDay()):0-(x.getDay()-d); if(p<0&&dOff>0){ week-=7; } if(p>0&&dOff<0){ week+=7; } x.setTime(x.getTime()+((dOff+week)*86400000)); } return x; }
function lZ(x){ return (x>9)?x:'0'+x; }
function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; }
function y2(x){ x=(x<500)?x+1900:x; return String(x).substring(2,4) }
function dT(){ if(fr==0){ fr=1; document.write('<b><span id="tP">'+eval(oT)+'</span></b>'); } tP.innerText=eval(oT); setTimeout('dT()',1000); }
function aP(x){ return (x>11)?'pm':'am'; }
var dN=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'),fr=0,oT="''+tH(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '+aP(tS().getHours())";
</script>

Erika

Kor
10-05-2003, 02:18 PM
there remainded some redundant code lines, but if it works fine, and you don't to make a contest art designe code :) leave it as it is, and save your time. Good luck, now :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum