Probleme d'affichage date et heure sur site

Résolu
ophoto Messages postés 68 Date d'inscription   Statut Membre Dernière intervention   -  
 mano -
Bonjour,

je crée un site sur lequel je voudrais faire apparaitre la date et heur, j'ai fais ceci :

<script language="javascript">
      function fClock()
      {
      MyClock = new Date;
      hours = MyClock.getHours();
      minutes = MyClock.getMinutes();
      seconds = MyClock.getSeconds();
      day = MyClock.getDate();
      dDate = MyClock.getDay();
      month = MyClock.getMonth();
      year = MyClock.getFullYear();
      tabDate=new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi");
      tabMonth=new Array("Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Décembre");
      AffMonth = tabMonth[month];
      VarDate = tabDate[dDate]+" "+day +" " + AffMonth + " " + year + "<br>";
      VarDate += hours + " h " + minutes +" : "+ seconds;
      if (document.getElementById){
      document.getElementById("oClock").innerHTML=VarDate;
      }
      setTimeout("fClock()", 500)
      }
      window.onload = fClock;
      </script>
      </p>
      <div align="center" id="oClock"></div>


ca fonctionne parfaitement sauf l'affichage par exemple lorsqu'il est 02 h 05 : 09 ca me note 2 h 5 : 9 comment faire pour que lorsque le chiffre et en dessous de 10 ca me rajoute un "0" devant ?
A voir également:

4 réponses

kiki.boss3 Messages postés 43 Date d'inscription   Statut Membre Dernière intervention   13
 
il faut faire ajouter le 0 comme suit:
if(hours < 0)
{
hours = "0" + hours;
}
2
ophoto Messages postés 68 Date d'inscription   Statut Membre Dernière intervention   35
 
ahhhhhhhh ok je vois mais peux tu me dire où je dois le placer pour heure, minute et seconde
0
kiki.boss3 Messages postés 43 Date d'inscription   Statut Membre Dernière intervention   13
 
placer le avant l'affichage de l'heure comme suit :
<script language="javascript">
function fClock()
{
MyClock = new Date;
hours = MyClock.getHours();
if(hours < 10)
{
hours = "0" + hours;
}//répéter ça pour tous les autre c-à-d : minutes, seconds (dand le code remplacer hours par minutes que pour seconds )
minutes = MyClock.getMinutes();
seconds = MyClock.getSeconds();
day = MyClock.getDate();
dDate = MyClock.getDay();
month = MyClock.getMonth();
year = MyClock.getFullYear();
tabDate=new Array("Dimanche","Lundi","Mardi","Mercredi","
Jeudi","Vendredi","Samedi");
tabMonth=new Array("Janvier","Fevrier","Mars","Avril","Mai
","Juin","Juillet","Aout","Septembre","O
ctobre","Novembre","Décembre");
AffMonth = tabMonth[month];
VarDate = tabDate[dDate]+" "+day +" " + AffMonth + " " + year + "<br>";
VarDate += hours + " h " + minutes +" : "+ seconds;
if (document.getElementById){
document.getElementById("oClock").innerHTML=VarDate;
}
setTimeout("fClock()", 500)
}
window.onload = fClock;
</script>
</p>
<div align="center" id="oClock"></div>
0
ophoto
 
super ca fonctionne merci
0
mano
 
program pour affichager at é héur
0