获取星期几的方法
第一种:
1 var str = ""; 2 var week = new Date().getDay(); 3 if (week == 0) { 4 str = "今天是星期日"; 5 } else if (week == 1) { 6 str = "今天是星期一"; 7 } else if (week == 2) { 8 str = "今天是星期二"; 9 } else if (week == 3) { 10 str = "今天是星期三"; 11 } else if (week == 4) { 12 str = "今天是星期四"; 13 } else if (week == 5) { 14 str = "今天是星期五"; 15 } else if (week == 6) { 16 str = "今天是星期六"; 17 } 18 name="code" class="javascript"> alert(str);</pre>
第二种:
var str = "今天是星期"; var week = new Date().getDay(); switch (week) { case 0 : str += "日"; break; case 1 : str += "一"; break; case 2 : str += "二"; break; case 3 : str += "三"; break; case 4 : str += "四"; break; case 5 : str += "五"; break; case 6 : str += "六"; break; } alert(str);
第三种:
1 var a = new Array("日", "一", "二", "三", "四", "五", "六"); 2 var week = new Date().getDay(); 3 var str = "今天是星期"+ a[week]; 4 alert(str);
第四种:
var str = "今天是星期" + "日一二三四五六".charAt(new Date().getDay());alert(str);
每一份努力都不会白费。