[JS] Pb avec les dates :(

Pb avec les dates :( [JS] - HTML/CSS - Programmation

Marsh Posté le 26-06-2006 à 17:57:06    

Salut a tous,
 
Je pense que j'ai une petite erreur, mais je n'arrive pas a la trouver :
 

Code :
  1. var curdate = new Date()
  2. var mday = curdate.getDate()
  3. var year = curdate.getFullYear()
  4. var month = curdate.getMonth()
  5. if(month == "0" ) { 
  6.      month_str = "Janvier"
  7.      }
  8. else if(month == "1" ) {
  9.      month_str = "Février"
  10.       }
  11. else if(month == "2" ) {
  12.      month_str = "Mars"
  13.      }
  14. else if(month == "3" ) {
  15.      month_str = "Avril"
  16.      }
  17. else if(month == "4" ) {
  18.      month_str = "Mai"
  19.      }
  20. else if(month == "5" ) {
  21.      month_str = "Juin"
  22.      }
  23. else if(month == "6" ) {
  24.      month_str = "Juillet"
  25.      }
  26. else if(month == "7" ) {
  27.      month_str = "Aout"   
  28.      }
  29. else if(month == "8" ) {
  30.      month_str = "Septembre"   
  31.      }
  32. else if(month == "9" ) {
  33.      month_str = "Octobre"   
  34.      }
  35. else if(month == "10" ) {
  36.      month_str = "Novembre"
  37.      }
  38. else {
  39.      month_str = "Décembre"         
  40.      }


 
Merci d'avance,
 
m.

Reply

Marsh Posté le 26-06-2006 à 17:57:06   

Reply

Marsh Posté le 26-06-2006 à 21:10:20    

Dans le sens ou je suis une grosse fainiasse et j'ai la flème de corriger ton code (il manque pleins de ; ca rend déjà ton code un peu plus clean :D)
 
j'ai préféré le simplifier :

Code :
  1. var curdate = new Date();
  2.     var mday = curdate.getDate();
  3.     var year = curdate.getFullYear();
  4.     var month = curdate.getMonth();
  5.  var monthArray = new Array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Décembre" );
  6.  var month_str = monthArray[month];

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed