joninho Posted May 11, 2006 at 12:25 PM Report #26857 Posted May 11, 2006 at 12:25 PM está aqui o source para quem quiser um relógio no seu site, a ser actualizado por segundo, as horas sao apresentadas consoante o local do cliente.. ou seja o relogio mostra as horas do seu computador. <script type="text/javascript"> //relogio function startTime() { var today=new Date() var h=today.getHours() var m=today.getMinutes() var s=today.getSeconds() // add a zero in front of numbers<10 m=checkTime(m) s=checkTime(s) document.getElementById('txt').innerHTML=h+":"+m+":"+s t=setTimeout('startTime()',500) } function checkTime(i) { if (i<10) {i="0" + i} return i } </script> </head> <body onload="startTime()"> <div id="txt"></div>
UnKnowN Posted May 11, 2006 at 01:01 PM Report #26862 Posted May 11, 2006 at 01:01 PM está aqui o source para quem quiser um relógio no seu site, a ser actualizado por segundo, as horas sao apresentadas consoante o local do cliente.. ou seja o relogio mostra as horas do seu computador. <script type="text/javascript"> //relogio function startTime() { var today=new Date() var h=today.getHours() var m=today.getMinutes() var s=today.getSeconds() // add a zero in front of numbers<10 m=checkTime(m) s=checkTime(s) document.getElementById('txt').innerHTML=h+":"+m+":"+s t=setTimeout('startTime()',500) } function checkTime(i) { if (i<10) {i="0" + i} return i } </script> </head> <body onload="startTime()"> <div id="txt"></div> Obrigado vou implementar talx 👍
joninho Posted May 11, 2006 at 04:53 PM Author Report #26889 Posted May 11, 2006 at 04:53 PM d nada 👍 eu tb andava à procura uma altura por isso decidi postar isto aí 🙂
UnKnowN Posted May 11, 2006 at 06:19 PM Report #26902 Posted May 11, 2006 at 06:19 PM d nada 👍 eu tb andava à procura uma altura por isso decidi postar isto aí 🙂 E fizeste tu se nao muito bem 😛
sandro_G Posted February 9, 2007 at 05:18 PM Report #81517 Posted February 9, 2007 at 05:18 PM Thanks..Curti ||I'm the devil25, I'm G and I'm sandro_G||
pedrosorio Posted March 30, 2008 at 10:21 PM Report #176392 Posted March 30, 2008 at 10:21 PM http://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock Da w3schools, é um sítio bastante bom para aprender linguagens relacionadas com a web. Não respondo a dúvidas por mensagem.
RicardoC Posted September 4, 2008 at 10:22 PM Report #208836 Posted September 4, 2008 at 10:22 PM esse código é igualzinho ao do meu site !!!
TheGlorious Posted September 5, 2008 at 08:02 AM Report #208870 Posted September 5, 2008 at 08:02 AM E o teu igualzinho ao da w3schools --' A inteligência não nasce connosco...
djthyrax Posted September 5, 2008 at 08:19 AM Report #208872 Posted September 5, 2008 at 08:19 AM E dispensa-se o off-topic por aqui. Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum!
RicardoC Posted September 7, 2008 at 12:11 PM Report #209249 Posted September 7, 2008 at 12:11 PM Desculpem-me...só para dizer então que trabalha muito bem 😉 100%
jarsantos Posted September 20, 2009 at 05:37 AM Report #287897 Posted September 20, 2009 at 05:37 AM Bem, hoje comecei a aprender javascript e como primeiro programa decidi fazer um relógio que achasse ser o mais eficiente possível. Este foi o resultado final: // Javascript Document // clock.js a clock that update only when it's really required and what is required. // What i mean with this is that for exemplo at the time 10:11:00 the clock just update the seconds and the minutes, not que hours. // the close doesn't update at a fixed time like almost every clocks, just update when the output is different form the actual output // // Author: João Santos (jarsantos@gmail.com) // // Everyone can use it and change it, but keep the credits please // Enjoy! var weekDays = new Array("Sunday", "Monday", "Thursday", "Wednesday", "Tuesday", "Friday", "Saturday") var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") function formatClock(int) { if(int < 10) { int = '0'+int } return int } function startClock() { var date = new Date() var time = new Array(date.getHours(), formatClock(date.getMinutes()), formatClock(date.getSeconds())) var weekDay = date.getDay() var month = date.getMonth() var day = new Array(weekDay, weekDays[weekDay], date.getDate(), month, months[month], date.getFullYear()) return new Array(time, day) } function updateClock(passado) { time = passado[0] day = passado[1] clockInfo = passado[2] date = new Date() time[2] = formatClock(date.getSeconds()) if(time[2] == '00') { time[1] = formatClock(date.getMinutes()) if(time[1] == '00') { time[0] = date.getHours() if(time[0] == 0) { day[0] = date.getDay() day[1] = weekDays[day[0]] day[2] = date.getDate() if(day[2] == 1) { day[3] = date.getMonth() day[4] = months[day[3]] if(day[3] == 1) { day[5] = date.getFullYear(); } } } } } document.getElementById('clock').innerHTML=time.join(':')+'<br />'+day[1]+', '+day[2]+' '+day[4]+' '+day[5] t=setTimeout('updateClock(new Array(time, day))',1000-(new Date().getMilliseconds())) } <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Clock Test</title> <script type="text/javascript" src="clock.js"></script> </head> <body onload="updateClock(startClock())"> <div id="clock"></div> </body> </html> Espero que gostem, deu-te um grande trabalho, mas também é um gozo ver o programa a trabalhar tão bem. Se testarem ao lado do que já foi colocado aqui neste tópico vão ver que este é mais rápido a actualizar e mais eficiente (não usa tanto o CPU)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now