/*********************************************** * 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. ***********************************************/ var weekdaystxtEN = ["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"] var monthstxtNO = ["januar", "februar", "mars", "april", "mai", "juni", "juli", "august", "september", "oktober", "november", "desember"] function showLocalTime(container, servermode, offsetMinutes, displayversion) { if( !document.getElementById || !document.getElementById(container) ) return this.container=document.getElementById(container) this.displayversion=displayversion var servertimestring='September 05, 2010 01:25:47' //alert(servertimestring); this.localtime = this.serverdate = new Date(servertimestring) this.localtime.setTime(this.serverdate.getTime() + offsetMinutes*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 hour = this.localtime.getHours() var minutes = this.localtime.getMinutes() var seconds = this.localtime.getSeconds() //if( hour == "00" && minutes == "00" && seconds == "01" ) //location.reload(true); if( hour == "0" ) hour = "00"; var ampm = (hour >= 12) ? "pm" : "am" var dayofweek = weekdaystxtEN[this.localtime.getDay()] var month = monthstxtNO[this.localtime.getMonth()] var monthdate = this.localtime.getDate() var year = this.localtime.getFullYear() var week = this.localtime.getWeek() this.container.innerHTML = "" + monthdate + ". " + month + " " + year + " " + hour + ":" + formatField(minutes) + ":" + formatField(seconds) + "" } 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 } Date.prototype.getWeek = function() { var onejan = new Date(this.getFullYear(),0,1); return Math.ceil((((this - onejan) / 86400000) + onejan.getDay())/7); }