← Desenvolvimento

javascript relógio solução de um problema

Lida 3461 vezes

Offline

icaro 
Membro
Mensagens 128 Gostos 0
Troféus totais: 26
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1 100 Posts

tenho este relógio no site, mas isto causa-me problemas quando muda a hora em Portugal, haverá alguma maneira de automatizar a coisa?

Código: [Seleccione]
Script Language="javascript">
<!--


data = new Date()

var horalxi=data.getUTCHours()
var horalxv=data.getUTCHours()+1
var min=data.getUTCMinutes()
var seg=data.getUTCSeconds()
var dia=data.getUTCDate()
var mes =data.getUTCMonth()
var diasem=data.getUTCDay()
var horajkt=data.getUTCHours()+7



var clockID = 0;  
function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

 
   
   document.theClock.theTime.value = ""
                                   + horalx + ":"
                                   + data.getUTCMinutes();
                                   
 

   document.theClock.theTime2.value=""
    +  horajkt + ":"
                                   + datae.getUTCMinutes();
                               
   

   clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

//-->


</script>
partindo daqui, tendo em conta que a hora adianta em relação UTC no último domingo de Março (1 da manhã) e que volta a ser igual UTC no último domingo de outubro (3 da manhã)... xiça isto está-me a dar conta da cabeça
Offline

Ze-dos-Trukes 
Membro
Mensagens 86 Gostos 0
Troféus totais: 25
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 5 Level 4 Level 3 Level 2 Level 1 50 Posts 10 Posts

Está aqui um outro, mas que tem o mesmo problema:
Código: [Seleccione]
<script language="JavaScript">

<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com

var clockID = 0;

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   var tDate = new Date();

   document.theClock.theTime.value = ""
                                   + tDate.getHours() + ":"
                                   + tDate.getMinutes() + ":"
                                   + tDate.getSeconds();
   
   clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

//-->


Dá-me a ideia k n vai ser assim tão simples...

Vais ter então k entrar com mais variáveis, nomeadamente em relação ao calendário, senão n vais conseguir dizer ao programa para ele considerar UTC ou UTC+/-1

O k quer dizer k talvez neste já consigas:
http://www.pageresource.com/jscript/jclock2.htm
:D
Offline

icaro 
Membro
Mensagens 128 Gostos 0
Troféus totais: 26
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1 100 Posts

[bom não era o que queria mas já ajuda
Código: [Seleccione]

data = new Date()
var hrlxv5 = new Date('march 27, 2005 0:59:59')
var hrlxi5 = new Date('october 30, 2005 2:59:59')
var hrlxv6 = new Date('march 26, 2006 0:59:59')
var hrlxi6 = new Date('october 29, 2006 2:59:59')
var hrlxv7 = new Date('march 25, 2007 0:59:59')
var hrlxi7 = new Date('october 28, 2007 2:59:59')
var horalx


if (data > hrlxv5 && data < hrlxi5)
{
horalx=data.getUTCHours()+1
}
else if (data > hrlxv6 && data < hrlxi6)
{
horalx=data.getUTCHours()+1
}
else if (data > hrlxv7 && data < hrlxi7)
{
horalx=data.getUTCHours()+1
}
else
{
horalx=data.getUTCHours()
}

Offline

Ze-dos-Trukes 
Membro
Mensagens 86 Gostos 0
Troféus totais: 25
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 5 Level 4 Level 3 Level 2 Level 1 50 Posts 10 Posts

Exacto.. assim consegues...
Tinhas k utilizar mais info, para definires as datas de mudança de horário ;)
Offline

icaro 
Membro
Mensagens 128 Gostos 0
Troféus totais: 26
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1 100 Posts

Citação de: "Ze-dos-Trukes"
Exacto.. assim consegues...
Tinhas k utilizar mais info, para definires as datas de mudança de horário ;)
mais...:roletarussa:

bom mas deixo aqui alguns sites que tratam dessa questão

http://www.merlyn.demon.co.uk/js-date5.htm
http://www.irt.org/script/281.htm
http://javascript.internet.com/clocks/date-time-long.html
http://www.csgnetwork.com/timezoneproginfo.html
Offline

-RJ- 
Membro
Mensagens 1188 Gostos 0
Troféus totais: 30
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

podes tentar este:

Código: [Seleccione]
<!-- Inìcio do CLOCK -->

<CENTER>
<SCRIPT Language="JavaScript">
<!--
var timerID = null;

function showtime(){
  var today=new Date()
  document.CLOCK.ALARM.value=today.toLocaleString()
  TimerID=setTimeout("showtime()",1000)
}
// -->
</SCRIPT>

<BODY onLoad="showtime()">
<FORM name="CLOCK"><INPUT name="ALARM" TYPE="TEXT" SIZE=34 VALUE="      Data + Relógio"></FORM>

</SCRIPT>
</CENTER>

<!-- Fim do CLOCK -->
Offline

icaro 
Membro
Mensagens 128 Gostos 0
Troféus totais: 26
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1 100 Posts

Assim já funciona (pelo menos até 2007)
Código: [Seleccione]
<Script Language="javascript">
<!--

function Relogio() {
 
data = new Date()

var hrlxv5 = new Date('march 27, 2005 0:59:59')
var hrlxi5 = new Date('october 30, 2005 2:59:59')
var hrlxv6 = new Date('march 26, 2006 0:59:59')
var hrlxi6 = new Date('october 29, 2006 2:59:59')
var hrlxv7 = new Date('march 25, 2007 0:59:59')
var hrlxi7 = new Date('october 28, 2007 2:59:59')

var minutos= data.getUTCMinutes()
var segundos= data.getUTCSeconds()


 
   var horalx
   
   if (data > hrlxv5 && data < hrlxi5)
{
horalx=data.getUTCHours()+1
}
else if (data > hrlxv6 && data < hrlxi6)
{
horalx=data.getUTCHours()+1
}
else if (data > hrlxv7 && data < hrlxi7)
{
horalx=data.getUTCHours()+1
}
else
{
horalx=data.getUTCHours()
}

if (horalx < 10)
{
horalx = "0" +  horalx
}
if (minutos < 10)
{
minutos = "0" + minutos
}
if (segundos < 10)
{
segundos = "0" + segundos
}
if (horajkt < 10)
{
horajkt = "0" + horajkt
}


   
  var rellx=  document.theClock.theTime.value = ""
                                   + horalx + ":"
                                   + minutos + ":"
                                   + segundos;
                                   
                               
   

 var Actualizar =setTimeout("Relogio()",  "1000");
}

//-->

</script>
<body onload="Relogio()"