Javascript Essentials Part 4


DATE and TIME

Regular Time and Date Full Script (Live)
<script language="JavaScript">
function tS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()+18000000); return x; } 
function tN(){ return new Date(); } 
function lZ(x){ return (x>9)?x:'0'+x; } 
function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } 
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'; } 
function y4(x){ return (x<500)?x+1900:x; } 
var dN=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'),mN=new Array('January','February','March','April','May','June','July','August','September','October','November','December'),fr=0,oT="dN[tS().getDay()]+' '+tS().getDate()+' '+mN[tS().getMonth()]+' '+y4(tS().getYear())+' '+':'+':'+' '+tH(tS().getHours())+':'+lZ(tS().getMinutes())+':'+lZ(tS().getSeconds())+' '+aP(tS().getHours())";
</script> 
<script language="JavaScript">
dT();
</script>
Date Script (Month, Date, Year)
<script language=JavaScript>
var months=new Array(13);months[1]="January";months[2]="February";
months[3]="March";months[4]="April";months[5]="May";months[6]="June";
months[7]="July";months[8]="August";months[9]="September";months[10]="October";
months[11]="November";months[12]="December";var time=new Date();
var lmonth=months[time.getMonth() + 1];var date=time.getDate();
var year=time.getYear();
if ((navigator.appName == "Microsoft Internet Explorer") && (year < 2000))
year="19" + year;if (navigator.appName == "Netscape")year=1900 + year;
document.write(lmonth + " ");
document.write(date + ", " + year);
</script>
Time script (Time(Hour,minutes,second), AM:PM) – Live
<SCRIPT>
function tick() {
var hours, minutes, seconds, ap;
var intHours, intMinutes, intSeconds;
var today;
today = new Date();
intHours = today.getHours();
intMinutes = today.getMinutes();
intSeconds = today.getSeconds();
if (intHours == 0) {
hours = "12:";
ap = "It's midnight";
} else if (intHours < 12) {
hours = intHours+":";
ap = " AM";
} else if (intHours == 12) {
hours = "12:";
ap = "It's noon";
} else {
intHours = intHours - 12
hours = intHours + ":";
ap = " PM";
}
if (intMinutes < 10) {
minutes = "0"+intMinutes+":";
} else {
minutes = intMinutes+":";
}
if (intSeconds < 10) {
seconds = "0"+intSeconds+" ";
} else {
seconds = intSeconds+" ";
}
timeString = hours+minutes+seconds+ap;
Clock.innerHTML = timeString;
window.setTimeout("tick();", 100);
}
window.onload = tick;
</SCRIPT>
<DIV id=Clock style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt"> </DIV>

Related Posts


1 thought on “Javascript Essentials Part 4

Leave a Reply

Your email address will not be published. Required fields are marked *