/*********************************************** * Local Time script- © Dynamic Drive (http://www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit http://www.dynamicdrive.com/ for this script and 100s more. ***********************************************/ /* In start() function on the top of the html page is the following: window.onload=showLocalTime. */ var weekdaystxt=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] var weekdaystxtshort=["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] var monthstxt=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] var monthstxtshort=["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] function showLocalTime(container, servermode, offsetMinutes, t111, t112, t121, t122, t131, t132, t141, t142, t151, t152, t161, t162, t171, t172, t181, t182, t191, t192, t201, t202, t211, t212, t221, t222, t231, t232, t241, t242, t251, t252, t261, t262, t271, t272, t281, t282, t291, t292, displayversion) { if (!document.getElementById || !document.getElementById(container)) return this.container=document.getElementById(container) this.displayversion=displayversion var servertimestring=(servermode=="server-php")? 'April 27, 2024 09:58:31' : (servermode=="server- ssi")? '' : '<%= Now() %>' this.localtime=this.serverdate=new Date(servertimestring) this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time this.t111=new Date(t111) this.t112=new Date(t112) this.t112= this.t112 - 1000*60*60 //To have t112 according to official dst ending hour. this.t121=new Date(t121) this.t122=new Date(t122) this.t122= this.t122 - 1000*60*60 this.t131=new Date(t131) this.t132=new Date(t132) this.t132= this.t132 - 1000*60*60 this.t141=new Date(t141) this.t142=new Date(t142) this.t142= this.t142 - 1000*60*60 this.t151=new Date(t151) this.t152=new Date(t152) this.t152= this.t152 - 1000*60*60 this.t161=new Date(t161) this.t162=new Date(t162) this.t162= this.t162 - 1000*60*60 this.t171=new Date(t171) this.t172=new Date(t172) this.t172= this.t172 - 1000*60*60 this.t181=new Date(t181) this.t182=new Date(t182) this.t182= this.t182 - 1000*60*60 this.t191=new Date(t191) this.t192=new Date(t192) this.t192= this.t192 - 1000*60*60 this.t201=new Date(t201) this.t202=new Date(t202) this.t202= this.t202 - 1000*60*60 this.t211=new Date(t211) this.t212=new Date(t212) this.t212= this.t212 - 1000*60*60 this.t221=new Date(t221) this.t222=new Date(t222) this.t222= this.t222 - 1000*60*60 this.t231=new Date(t231) this.t232=new Date(t232) this.t232= this.t232 - 1000*60*60 this.t241=new Date(t241) this.t242=new Date(t242) this.t242= this.t242 - 1000*60*60 this.t251=new Date(t251) this.t252=new Date(t252) this.t252= this.t252 - 1000*60*60 this.t261=new Date(t261) this.t262=new Date(t262) this.t262= this.t262 - 1000*60*60 this.t271=new Date(t271) this.t272=new Date(t272) this.t272= this.t272 - 1000*60*60 this.t281=new Date(t281) this.t282=new Date(t282) this.t282= this.t282 - 1000*60*60 this.t291=new Date(t291) this.t292=new Date(t292) this.t292= this.t292 - 1000*60*60 this.daylightsaving = 0 if ((this.t111 < this.localtime && this.t112 > this.localtime) || (this.t121 < this.localtime && this.t122 > this.localtime) || (this.t131 < this.localtime && this.t132 > this.localtime) || (this.t141 < this.localtime && this.t142 > this.localtime) || (this.t151 < this.localtime && this.t152 > this.localtime) || (this.t161 < this.localtime && this.t162 > this.localtime) || (this.t171 < this.localtime && this.t172 > this.localtime) || (this.t181 < this.localtime && this.t182 > this.localtime) || (this.t191 < this.localtime && this.t192 > this.localtime) || (this.t201 < this.localtime && this.t202 > this.localtime) || (this.t211 < this.localtime && this.t212 > this.localtime) || (this.t221 < this.localtime && this.t222 > this.localtime) || (this.t231 < this.localtime && this.t232 > this.localtime) || (this.t241 < this.localtime && this.t242 > this.localtime) || (this.t251 < this.localtime && this.t252 > this.localtime) || (this.t261 < this.localtime && this.t262 > this.localtime) || (this.t271 < this.localtime && this.t272 > this.localtime) || (this.t281 < this.localtime && this.t282 > this.localtime) || (this.t291 < this.localtime && this.t292 > this.localtime)) { (this.daylightsaving = 1); } this.localtime.setTime(this.serverdate.getTime()+this.daylightsaving*60*60*1000) this.updateTime() this.updateContainer() } showLocalTime.prototype.updateTime=function() { var thisobj=this this.localtime.setSeconds(this.localtime.getSeconds()+1) setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second } showLocalTime.prototype.updateContainer=function() { var thisobj=this var date=this.localtime.getDate() var hour=this.localtime.getHours() var minutes=this.localtime.getMinutes() var seconds=this.localtime.getSeconds() var dayofweek=weekdaystxt[this.localtime.getDay()] var dayofweekshort=weekdaystxtshort[this.localtime.getDay()] var monthofyear=monthstxt[this.localtime.getMonth()] var monthofyearshort=monthstxtshort[this.localtime.getMonth()] var year=this.localtime.getFullYear() if (this.displayversion=="short") { this.container.innerHTML=format24(hour)+":"+format24(minutes)+" ("+dayofweekshort+")"; } if (this.displayversion=="long") { this.container.innerHTML=dayofweek+", "+date+" "+monthofyear+" "+year+", "+format24(hour)+":"+format24(minutes)+":"+format24(seconds); } if (this.displayversion=="timezone12") { this.container.innerHTML= format12(hour, 1)+":"+format12(minutes)+":"+format12(seconds)+""+format12ampm(hour)+""; } if (this.displayversion=="timezone24") { this.container.innerHTML= format24(hour)+":"+format24(minutes)+":"+format24(seconds); } if (this.displayversion=="timezone_date") { this.container.innerHTML= dayofweekshort+", "+date+" "+monthofyearshort+" "+year; } if (this.displayversion=="timemap_date") { this.container.innerHTML= dayofweekshort+", "+date+" "+monthofyearshort; } if (this.displayversion=="datetime12") { this.container.innerHTML=dayofweek+", "+date+" "+monthofyear+" "+year+", "+format12(hour, 1)+":"+format12(minutes)+":"+format12(seconds)+" "+""+format12ampm(hour)+""; } if (this.displayversion=="datetime24") { this.container.innerHTML=dayofweek+", "+date+" "+monthofyear+" "+year+", "+format24(hour)+":"+format24(minutes)+":"+format24(seconds); } if (this.displayversion=="utc12") { this.container.innerHTML=dayofweekshort+", "+date+" "+monthofyearshort+" "+year+", "+format12(hour, 1)+":"+format12(minutes)+":"+format12(seconds)+" "+""+format12ampm(hour)+""; } if (this.displayversion=="utc24") { this.container.innerHTML=dayofweekshort+", "+date+" "+monthofyearshort+" "+year+", "+format24(hour)+":"+format24(minutes)+":"+format24(seconds); } setTimeout(function(){thisobj.updateContainer()}, 1000); //update container every second } function format24(num) { var digit = (num<=9)? "0"+num : num; return digit; } function format12(num, isHour) { if (typeof isHour!="undefined") { var hour = (num > 12)? num-12 : num return (hour==0)? 12 : hour } return (num<=9)? "0"+num : num; //if this is minute or sec field } function format12ampm(num) { var ampm = (num >= 12)? "pm" : "am"; return ampm; }