Problèmes affichage horloge en direct

santille
Invité n'ayant pas de compte PHPfrance

13 mai 2005, 18:35

Bonjour,
Ci-dessous le code qui me pose problème. Je voudrais afficher l'heure qu'il fait à Tokyo (GMT+9, sauf erreur) mais je ne sais pas comment le faire...

Merci d'avance.

seb

============================================
<script language="Javascript">

var timerID = null
var timerRunning = false

function stopclock(){
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}

function startclock01(){
stopclock()
showtime()
}

function showtime(){
var now = new Date()
var minutes = now.getMinutes()
var seconds = now.getSeconds()
var GMT = (now.getHours() + 00)

var hoursGMT = (GMT + 00)
var timeValueGMT = "" + ( (hoursGMT > 12) ? hoursGMT - 12 : hoursGMT )
timeValueGMT += ( (minutes < 10) ? ":0" : ":" ) + minutes
timeValueGMT += ( (seconds < 10) ? ":0" : ":" ) + seconds
timeValueGMT += (hoursGMT >= 12) ? " PM" : " AM"
document.clock.faceGMT.value = timeValueGMT

var hoursEET = (GMT - 01)
var timeValueEET = "" + ( (hoursEET > 12) ? hoursEET - 12 : hoursEET )
timeValueEET += ( (minutes < 10) ? ":0" : ":" ) + minutes
timeValueEET += ( (seconds < 10) ? ":0" : ":" ) + seconds
timeValueEET += (hoursEET >= 12) ? " PM" : " AM"
document.clock.faceEET.value = timeValueEET

var hoursCET = (GMT - 09)
var timeValueCET = "" + ( (hoursCET > 12) ? hoursCET - 12 : hoursCET )
timeValueCET += ( (minutes < 10) ? ":0" : ":" ) + minutes
timeValueCET += ( (seconds < 10) ? ":0" : ":" ) + seconds
timeValueCET += (hoursCET >= 12) ? " PM" : " AM"
document.clock.faceCET.value = timeValueCET


var hoursPST = (GMT - 06)
var timeValuePST = "" + ( (hoursPST > 12) ? hoursPST - 12 : hoursPST )
timeValuePST += ( (minutes < 10) ? ":0" : ":" ) + minutes
timeValuePST += ( (seconds < 10) ? ":0" : ":" ) + seconds
timeValuePST += (hoursPST >= 12) ? " PM" : " AM"
document.clock.facePST.value = timeValuePST


timerID = setTimeout("showtime()",1000)
timerRunning = true
}
</script>
--------------------------------------------
<body onload="startclock01()">


<table width="730" border=0 cellpadding=0 cellspacing=0>
<form name=clock onsubmit=0>
<tr>
<td valign=top>

<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="td1">GMT+02 Zürich</td>
<td><input type=text name=faceGMT size=9 class="input"></td>
</tr>
</table>

</td>
<td valign=top>

<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="td2">GMT+01 London</td>
<td><input type=text name=faceEET size=9 class="input"></td>
</tr>
</table>

</td>
<td valign=top>

<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="td3">GMT+09 Tokyo</td>
<td><input type=text name=faceCET size=9 class="input"></td>
</tr>
</table>

</td>
<td valign=top>

<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="td4">GMT-04 New York</td>
<td><input type=text name=facePST size=9 class="input"></td>
</tr>
</table>

</td>
</tr>
</form>
</table>
</body>
</html>
==============================================

Modérateur PHPfrance
Modérateur PHPfrance | 6373 Messages

13 mai 2005, 21:09

il faut d'abord que tu postes ton code entre balises

Code : Tout sélectionner

[code]
[/code] afin de le rendre plus lisible
qu'éventuellement tu l'allèges pour ne garder que ce qui est utile
et surtout que tu précises où tu as un problème

si tu as tout ce code c'est que tu as déjà fait des essais donc tu as peut-être une idée du problème... ou des questions plus précises à poser

afbilou
Invité n'ayant pas de compte PHPfrance

14 mai 2005, 04:13

Tu ne sais pas qu'une instruction javascript se termine par ";" ?

D'autre part <script language="javascript"> est obsolete.
Il faut mettre <script type="text/javascript"> maintenant.