/*********************************************** * 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. * .............................................. * This script was heavily modified by Neil Dempster. * Added: Extension to numbers (e.g., 1st, 2nd, etc.) * Added: Flexibility to display format * Added: 24 hour clock in display * Added: Automatic DST routine * Added: Check for Holiday and update container * Added: Check for Weekend and update container ***********************************************/ arday = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") ardate = new Array("0th","1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st") armonth = new Array("January ","February ","March ","April ","May ","June ","July ","August ","September ", "October ","November ","December ") daysmonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31) daysmonthLY = new Array(31,29,31,30,31,30,31,31,30,31,30,31) var today = new Date(); var year = today.getYear(); var DSTstart = new Date(year,3-1,NthDay(2,1,3,year),2,0,0); var DSTend = new Date(year,11-1,NthDay(1,1,11,year),2,0,0); var DSTstartMS = getMS(DSTstart); var DSTendMS = getMS(DSTend); var offset = (60); var todayMS = getMS(today); if (todayMS > DSTstartMS && todayMS < DSTendMS) offset = offset-60; function TimeZone(tz) { switch (tz) { case 480: return 60 break case 420: return 0 break case 360: return -60 break case 300: return -120 break } } function check_holiday (dt_date) { // get simple dates (month/date) var n_date = dt_date.getDate(), n_month = dt_date.getMonth() + 1; var s_date1 = n_month + '/' + n_date; if ( s_date1 == '1/1' // New Year's Day || s_date1 == '7/4' // Independence Day || s_date1 == '12/25' // Christmas Day ) return true; // weekday from beginning of the month (month/num/day) var n_wday = dt_date.getDay(), n_wnum = Math.floor((n_date - 1) / 7) + 1; var s_date2 = n_month + '/' + n_wnum + '/' + n_wday; if ( s_date2 == '9/1/1' // Labor Day, first Monday in September || s_date2 == '11/4/4' // Thanksgiving Day, fourth Thursday in November ) return true; // weekday number from end of the month (month/num/day) var dt_temp = new Date (dt_date); dt_temp.setDate(1); dt_temp.setMonth(dt_temp.getMonth() + 1); dt_temp.setDate(dt_temp.getDate() - 1); n_wnum = Math.floor((dt_temp.getDate() - n_date - 1) / 7) + 1; var s_date3 = n_month + '/' + n_wnum + '/' + n_wday; if ( s_date3 == '5/1/1' // Memorial Day, last Monday in May ) return true; return false; } function LeapYear(year) { if ((year/4) != Math.floor(year/4)) return false; if ((year/100) != Math.floor(year/100)) return true; if ((year/400) != Math.floor(year/400)) return false; return true; } function DayOfWeek(day,month,year) { var a = Math.floor((14 - month)/12); var y = year - a; var m = month + 12*a - 2; var d = (day + y + Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400) + Math.floor((31*m)/12)) % 7; return d+1; } function NthDay(nth,weekday,month,year) { if (nth > 0) return (nth-1)*7 + 1 + (7 + weekday - DayOfWeek((nth-1)*7 + 1,month,year))%7; if (LeapYear(year)) var days = daysmonthLY; else var days = daysofmonth; return days - (DayOfWeek(days,month,year) - weekday + 7)%7; } function getMS(date) { return Date.UTC(date.getYear(),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds()) } function showLocalTime(container, servermode, displayversion){ if (!document.getElementById || !document.getElementById(container)) return this.container=document.getElementById(container) this.displayversion=displayversion var servertimestring=(servermode=="server-php")? 'September 06, 2010 09:47:17' : (servermode=="server-ssi")? '' : '<%= Now() %>' this.localtime=this.serverdate=new Date(servertimestring) //var timestamp = this.localtime.getTimezoneOffset() //offset=TimeZone(this.serverdate.getGMTOffset()) this.localtime.setTime(this.serverdate.getTime()+offset*60*1000) //add user offset to server time 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 if (this.displayversion=="long") this.container.innerHTML=this.localtime.toLocaleString() else{ var month=this.localtime.getMonth() var date=this.localtime.getDate() var day=this.localtime.getDay() var year=this.localtime.getYear() var hour=this.localtime.getHours() var minutes=this.localtime.getMinutes() var seconds=this.localtime.getSeconds() var ampm=(hour>=12)? "pm" : "am" if (check_holiday(today)) this.container.innerHTML="Date: "+arday[day]+", "+armonth[month]+" "+ardate[date]+", "+year+'
'+"Time: "+formatField(hour, 1)+":"+formatField(minutes)+" "+ampm+" ["+formatHour(hour)+":"+formatMinute(minutes)+"]"+'
'+"Note: Today is a holiday in the USA and our office is closed." else if (day=='6') this.container.innerHTML="Date: "+arday[day]+", "+armonth[month]+" "+ardate[date]+", "+year+'
'+"Time: "+formatField(hour, 1)+":"+formatField(minutes)+" "+ampm+" ["+formatHour(hour)+":"+formatMinute(minutes)+"]"+'
'+"Note: Today is Saturday and our office is currently closed." else if (day=='0') this.container.innerHTML="Date: "+arday[day]+", "+armonth[month]+" "+ardate[date]+", "+year+'
'+"Time: "+formatField(hour, 1)+":"+formatField(minutes)+" "+ampm+" ["+formatHour(hour)+":"+formatMinute(minutes)+"]"+'
'+"Note: Today is Sunday and our office is currently closed." else this.container.innerHTML="Date: "+arday[day]+", "+armonth[month]+" "+ardate[date]+", "+year+'
'+"Time: "+formatField(hour, 1)+":"+formatField(minutes)+" "+ampm+" ["+formatHour(hour)+":"+formatMinute(minutes)+"]" } setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second } function formatField(num, isHour){ if (typeof isHour!="undefined"){ //if this is the hour field 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 formatHour(num){ return (num<=9)? "0"+num : num } function formatMinute(num){ return (num<=9)? "0"+num : num }