var timer = 0; function stop(){ clearTimeout(timer); } function timeCheck() { var onehour = 1000*60*60; // this sets UTC time to EST var d = new Date(new Date().getTime() + 10*onehour); var isDST = false; // handle DST // Sunday = 0 to Saturday = 6 var day = d.getUTCDay(); // 1 - 31 var date = d.getUTCDate(); // 0 - 11 var month = d.getUTCMonth(); // 0 - 23 var hour = d.getUTCHours(); // find first and last Sunday var firstSun = date - day; var lastSun = date - day; firstSun = firstSun % 7; while (firstSun <= 0) { firstSun += 7; } // don't need last saturday anymore // use 31, as only March and October were used in calculation, and both have 31 days while (lastSun < 31-6){ lastSun += 7; } // is EST if after 1st Sunday of April at 2am (+11) (EST), and before 1st Sunday of October at 3am (EDST time) (only +10) if ((month > 3 || (month == 3 && (date > firstSun || (date == firstSun && hour >= 2)))) && (month < 9 || (month == 9 && (date < firstSun || (date == firstSun && hour < 2))))){ isDST = false; } else { isDST = true; d = new Date(d.getTime() + onehour); } var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; // convert to AM/PM time var hours = d.getUTCHours(); var suffix = 'AM'; if (hours >= 12) { suffix = 'PM'; if (hours > 12) hours -= 12; } if (hours == 0) hours += 12; var minutes = d.getUTCMinutes(); var seconds = d.getUTCSeconds(); if (minutes < 10) minutes = '0' + minutes; if (seconds < 10) seconds = '0' + seconds; // create the time string var dateTime = days[d.getUTCDay()] + ', ' + d.getUTCDate() + ' ' + months[d.getUTCMonth()] + ', ' + d.getUTCFullYear() + ' - ' + hours + ':' + minutes + ':' + seconds + ' ' + suffix; // display the time document.getElementById('time').innerHTML = 'Melbourne Time:     ' + dateTime; timer = setTimeout(timeCheck, 1000); /* var firstSat = date - (day+1)//find the first saturday in the month while (firstSat > 0) firstSat+=-7 if (firstSat < 1) firstSat+=7 if ((((month == 4) && (date >= firstSat)) || month > 4) && (month < 11 || ((month == 10) && day <= lastSat)))//if it is not DST time hour += 10 else hour += 11 return; var d = new Date()//the date var secs = d.getUTCSeconds()//UTC secs var mins = d.getUTCMinutes()//UTC mins var hour = d.getUTCHours()//UTC hours var day = d.getUTCDay()//UTC day var date = d.getUTCDate()//UTC date var month = d.getUTCMonth()//UTC month (1 is Jan etc) var year = d.getUTCFullYear()//UTC year (4-digit) var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")//list of the days var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December")//list of the months var end = ""//AM or PM var space = " "//a space var c = ":"//a colon var comma = ", "// a comma var dash = " - "// a dash var leap=0//is it a leap year if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) leap=1//it is a leap year secs = ((secs < 10) ? "0" : "") + secs//put a zero in front mins = ((mins < 10) ? "0" : "") + mins//put a zero in front //////////////////////daylight savings stuff//////////////////////////////// var lastSat = date - (day+1)//find the last saturday in the month while (lastSat < 32) lastSat+=7 if (lastSat > 31) lastSat+=-7 var firstSat = date - (day+1)//find the first saturday in the month while (firstSat > 0) firstSat+=-7 if (firstSat < 1) firstSat+=7 if ((((month == 4) && (date >= firstSat)) || month > 4) && (month < 11 || ((month == 10) && day <= lastSat)))//if it is not DST time hour += 10 else hour += 11 return; //////////end of months and years, etc stuff///////////////////////////////////// if (((month == 4) || (month == 6) || (month == 9) || (month == 11)) && (date==31)) date = 1, month ++; if (((month == 2) && (date > 28)) && (leap == 0)) date = 1, month ++; if ((month == 2) && (date > 29)) date = 1, month++; if (hour < 0) hour += 24, date --; if ((date == 32) && (month == 12)) month = 1, date = 1, year++; if (date == 32) date = 1, month++; if ((date < 1) && (month == 1)) month = 12, date = 31, year--; if (date < 1) date = 31, month --; if (((month == 4) || (month == 6) || (month== 9) || (month == 11)) && (date == 31)) date = 30; if ((month == 2) && (date > 28)) date = 29; if (((month == 2) && (date > 28)) && (leap != 0)) date=28; //////////////////makes a variable to show in element////////////////////// var dateTime=days[day]+comma+date+space+months[month]+comma+year+dash if (hour>=12 && hour<24) end = " PM" else end = " AM" while (hour>12) hour-=12 dateTime+=hour+c+mins+c+secs+end document.getElementById('time').innerHTML = dateTime//sets 'time' to to the date and time timer = setTimeout("timeCheck()",1000)//changes time every second */ }