Afficher la date en javascript
Bonjour
J'ai un code pour afficher l'heure de tous les pays du monde qui fonctionne tr�s bien et il doit afficher la date mais je suis nul en javascript donc je ne sais pas comment afficher la date. J'ai mis <spant id="date"></span> ou <spant id="hours"></span> mais sa ne fontionne pas
Voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <script>
var date = new Date()
var gmtLocal;
function temps(){
date = new Date();
var outputs = document.getElementsByClassName("hours");
for(var i=0;i<outputs.length;i++){
outputs[i].innerHTML = getFormatedDate(outputs[i].id);
}
}
gmtLocal = -date.getTimezoneOffset() / 60;
if(document.getElementById("gmtlocal")){
document.getElementById("gmtlocal").innerHTML = "GMT " + ((gmtLocal < 0) ? "-" : "+") + gmtLocal;
}
if(document.getElementById("local")){
document.getElementById("local").id = gmtLocal;
}
setInterval(temps, 1000);
function getFormatedDate(gmt){
var dateTmp = new Date(date.getTime() + ((gmt - gmtLocal) * 3600 * 1000));
var str = "";
str += padTo2(dateTmp.getHours()) + ":" + padTo2(dateTmp.getMinutes()) + ":" + padTo2(dateTmp.getSeconds());
return str;
}
function padTo2(num){
if(num < 10){
return "0" + num;
}
else{
return num + "";
}
}
</script> |
Je vous remercie d'avance
Max