Forum de discussion
Forum « Programmation Javascript » (archives)
Problèmes horloge en direct
Envoyé: 13 mai 2005, 12h05 par santille
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>
==============================================
Réponses
|