Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

faezinha

Data e Hora

Recommended Posts

Oi Galera! To com um problema, coloquei no meu site data e hora feitos em JavaScript. Só que vamos supor que eu acesse o site as 14:15,por exemplo, ele não atualiza.Mesmo que tenha passado meia-hora ele continua nos 14:15.Para atualizar precisa dar F5. Tem como fazer a data e a hora atualizarem sozinhas? Ah e mais uma coisinha, tem como colocar o zero na frente dos numeros, exemplo ao invés de 14:9 ficar 14:09.Valeu galera vcs me ajudam muito> Parabéns e valeu mesmo!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara tenho esse script, só não me pergunte como alterar pq peguei pronto.

<script language="JavaScript">
<!--

/*
Upper Left Corner Live Clock Script-
© Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

function show5(){
if (!document.layers&&!document.all)
return;
var Digital=new Date();
var hours=Digital.getHours();
var minutes=Digital.getMinutes();
var seconds=Digital.getSeconds();
var dn="";//"AM";
//if (hours>12){
//dn="PM";
//hours=hours-12;
//}
//if (hours==0)
//hours=12;
if (minutes<=9)
minutes="0"+minutes;
if (seconds<=9)
seconds="0"+seconds;
//change font size here to your desire
myclock="<font size='2' face='Arial' ><font size='1'>São:</font>"+hours+"h"+minutes+"m"
+seconds+"s"+dn+"</font>";
if (document.layers){
document.layers.liveclock.document.write(myclock);
document.layers.liveclock.document.close();
}
else if (document.all)
liveclock.innerHTML=myclock;
setTimeout("show5()",1000);
}

//-->
</script>

você pode tb dar uma procurada no Código Livre,lá tem alguns exemplos.

 

 

Valeu?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Se tu está colocando a hora como se fosse parte da página o correto é que ela fique parada exatamente na hora que a pagina foi carregada, pois não tem lógica tu atualizar a hora da página sem atualizar a página...

 

Mas se tu está querendo colocar a hora como se fosse um reloginho, como um serviço, tambem vale a pena lembrar que nem todo mundo está na mesma hora que a gente, quem acessa da região norte, por exemplo, pode estar duas ou três horas mais adiantados que nós... Fora do Brasil, nem se fala... Mas se tu quer dizer assim: Hora em São Paulo: 12:45, ai fica ok...

 

Toma um reloginho legal... (não é meu não)...

 

<html>

<head>

<title>: : : m e g a . r s : : : model agency : : :                                                                                                       </title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link rel="stylesheet" href="css/links.css" type="text/css">

</head>

 

<body bgcolor="#000000" text="#FFFFFF">

<script language=JavaScript>

dCol='ffffff';//date colour.

fCol='999999';//face colour.

sCol='ff0000';//seconds colour.

mCol='ffffff';//minutes colour.

hCol='ffffff';//hours colour.

ClockHeight=40;

ClockWidth=60;

ClockFromMouseY=50;

ClockFromMouseX=120;

 

//Alter nothing below! Alignments will be lost!

 

d=new Array("DOMINGO","SEGUNDA","TERÇA","QUARTA","QUINTA","SEXTA","SÁBADO");

m=new Array("JANEIRO","FEVEREIRO","MARÇO","ABRIL","MAIO","JUNHO","JULHO","AGOSTO","SETEMBRO","OUTUBRO","NOVEMBRO","DEZEMBRO");

date=new Date();

day=date.getDate();

year=date.getYear();

if (year < 2000) year=year+1900;

TodaysDate=" "+d[date.getDay()]+" "+day+" "+m[date.getMonth()]+" "+year;

D=TodaysDate.split('');

H='...';

H=H.split('');

M='....';

M=M.split('');

S='.....';

S=S.split('');

Face='1 2 - 4 5 | 7 8 - 10 11 |';

font='Verdana';

size=1;

speed=0.7;

ns=(document.layers);

ie=(document.all);

Face=Face.split(' ');

n=Face.length;

a=size*10;

ymouse=50;

xmouse=50;

scrll=0;

props="<font face="+font+" size="+size+" color="+fCol+"><B>";

props2="<font face="+font+" size="+size+" color="+dCol+"><B>";

Split=360/n;

Dsplit=360/D.length;

HandHeight=ClockHeight/4.5

HandWidth=ClockWidth/4.5

HandY=-7;

HandX=-2.5;

scrll=0;

step=0.04;

currStep=0;

y=new Array();x=new Array();Y=new Array();X=new Array();

for (i=0; i < n; i++){y=0;x=0;Y=0;X=0}

Dy=new Array();Dx=new Array();DY=new Array();DX=new Array();

for (i=0; i < D.length; i++){Dy=0;Dx=0;DY=0;DX=0}

if (ns){

for (i=0; i < D.length; i++)

document.write('<layer name="nsDate'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props2+D+'</font></center></layer>');

for (i=0; i < n; i++)

document.write('<layer name="nsFace'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+Face+'</font></center></layer>');

for (i=0; i < S.length; i++)

document.write('<layer name=nsSeconds'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+sCol+'><center><b>'+S+'</b></center></font></layer>');

for (i=0; i < M.length; i++)

document.write('<layer name=nsMinutes'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+mCol+'><center><b>'+M+'</b></center></font></layer>');

for (i=0; i < H.length; i++)

document.write('<layer name=nsHours'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+hCol+'><center><b>'+H+'</b></center></font></layer>');

}

if (ie){

document.write('<div id="Od" style="position:absolute;top:0px;left:0px"><div style="position:relative">');

for (i=0; i < D.length; i++)

document.write('<div id="ieDate" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props2+D+'</B></font></div>');

document.write('</div></div>');

document.write('<div id="Of" style="position:absolute;top:0px;left:0px"><div style="position:relative">');

for (i=0; i < n; i++)

document.write('<div id="ieFace" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props+Face+'</B></font></div>');

document.write('</div></div>');

document.write('<div id="Oh" style="position:absolute;top:0px;left:0px"><div style="position:relative">');

for (i=0; i < H.length; i++)

document.write('<div id="ieHours" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+hCol+';text-align:center;font-weight:bold">'+H+'</div>');

document.write('</div></div>');

document.write('<div id="Om" style="position:absolute;top:0px;left:0px"><div style="position:relative">');

for (i=0; i < M.length; i++)

document.write('<div id="ieMinutes" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+mCol+';text-align:center;font-weight:bold">'+M+'</div>');

document.write('</div></div>')

document.write('<div id="Os" style="position:absolute;top:0px;left:0px"><div style="position:relative">');

for (i=0; i < S.length; i++)

document.write('<div id="ieSeconds" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+sCol+';text-align:center;font-weight:bold">'+S+'</div>');

document.write('</div></div>')

}

(ns)?window.captureEvents(Event.MOUSEMOVE):0;

function Mouse(evnt){

ymouse = (ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY;

xmouse = (ns)?evnt.pageX+ClockFromMouseX:event.x+ClockFromMouseX;

}

(ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse;

function ClockAndAssign(){

time = new Date ();

secs = time.getSeconds();

sec = -1.57 + Math.PI * secs/30;

mins = time.getMinutes();

min = -1.57 + Math.PI * mins/30;

hr = time.getHours();

hrs = -1.575 + Math.PI * hr/6+Math.PI*parseInt(time.getMinutes())/360;

if (ie){

Od.style.top=window.document.body.scrollTop;

Of.style.top=window.document.body.scrollTop;

Oh.style.top=window.document.body.scrollTop;

Om.style.top=window.document.body.scrollTop;

Os.style.top=window.document.body.scrollTop;

}

for (i=0; i < n; i++){

var F=(ns)?document.layers['nsFace'+i]:ieFace.style;

F.top=y + ClockHeight*Math.sin(-1.0471 + i*Split*Math.PI/180)+scrll;

F.left=x + ClockWidth*Math.cos(-1.0471 + i*Split*Math.PI/180);

}

for (i=0; i < H.length; i++){

var HL=(ns)?document.layers['nsHours'+i]:ieHours.style;

HL.top=y+HandY+(i*HandHeight)*Math.sin(hrs)+scrll;

HL.left=x+HandX+(i*HandWidth)*Math.cos(hrs);

}

for (i=0; i < M.length; i++){

var ML=(ns)?document.layers['nsMinutes'+i]:ieMinutes.style;

ML.top=y+HandY+(i*HandHeight)*Math.sin(min)+scrll;

ML.left=x+HandX+(i*HandWidth)*Math.cos(min);

}

for (i=0; i < S.length; i++){

var SL=(ns)?document.layers['nsSeconds'+i]:ieSeconds.style;

SL.top=y+HandY+(i*HandHeight)*Math.sin(sec)+scrll;

SL.left=x+HandX+(i*HandWidth)*Math.cos(sec);

}

for (i=0; i < D.length; i++){

var DL=(ns)?document.layers['nsDate'+i]:ieDate.style;

DL.top=Dy + ClockHeight*1.5*Math.sin(currStep+i*Dsplit*Math.PI/180)+scrll;

DL.left=Dx + ClockWidth*1.5*Math.cos(currStep+i*Dsplit*Math.PI/180);

}

currStep-=step;

}

function Delay(){

scrll=(ns)?window.pageYOffset:0;

Dy[0]=Math.round(DY[0]+=((ymouse)-DY[0])*speed);

Dx[0]=Math.round(DX[0]+=((xmouse)-DX[0])*speed);

for (i=1; i < D.length; i++){

Dy=Math.round(DY+=(Dy[i-1]-DY)*speed);

Dx=Math.round(DX+=(Dx[i-1]-DX)*speed);

}

y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed);

x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed);

for (i=1; i < n; i++){

y=Math.round(Y+=(y[i-1]-Y)*speed);

x=Math.round(X+=(x[i-1]-X)*speed);

}

ClockAndAssign();

setTimeout('Delay()',20);

}

if (ns||ie)window.onload=Delay;

</SCRIPT>

<style>

.intro{

position:absolute;

left:0;

top:0;

layer-background-color:black;

background-color:black;

border:0.1px solid black

}

</style>

 

<div id="i1" class="intro" style="background-color: #000000"></div>

<div id="i2" class="intro" style="background-color: #000000"></div>

 

<table width="600" border="0" align="center" height="100%">

<tr>

<td>

<div align="center"><font face="Verdana, Tahoma, Arial" size="1">Bem-vindo

a<br>

<br>

<br>

<a href="mega.htm" target="_top"><img src="images/logo_mega.gif" width="385" height="71" alt="Entre" border="0"></a>

</font></div>

</td>

</tr>

<tr>

<td valign="bottom">

<div align="center"><font face="Tahoma" size="1">Resolução mínima de 800x600

  |   © Copyright 2002 <b><a href="contato.htm" target="_blank">mega.rs</a>

& <a href="ziper.htm" target="_blank">Zíper publicidade&design</a></b> 

|   <font class="pequeno">Todos os direitos reservados</font></font></div>

</td>

</tr>

</table>

</body>

</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.