JS - 获取当前是星期几

目录

var s ="";
switch((new Date()).getDay()){
  case 0: s = "星期日";break;
  case 1: s = "星期一";break;
  case 2: s = "星期二";break;
  case 3: s = "星期三";break;
  case 4: s = "星期四";break;
  case 5: s = "星期五";break;
  case 6: s = "星期六";break;
}
alert(s);

或者这样:

var day = time.getDay();
    var weekDesc = new Array("星期天","星期一","星期二","星期三","星期四","星期五","星期六");
    for(var i=0;i<weekDesc.length;i++){
        if(day==i){
        document.getElementById("time").innerHTML="今天是:"+weekDesc[i];   
        }
    }

又或者这样

var weekDay = "日一二三四五六".split("")[new Date().getDay()];
alert(weekDay);

反正就是一个思路。

标签: javascript

声明:本博客如无特殊说明皆为原创,转载请注明来源:JS - 获取当前是星期几谢谢!

相关文章

发表评论:

icon_question.pngicon_razz.pngicon_sad.pngicon_evil.pngicon_exclaim.pngicon_smile.pngicon_redface.pngicon_biggrin.pngicon_surprised.pngicon_eek.pngicon_confused.pngicon_cool.pngicon_lol.pngicon_mad.pngicon_twisted.pngicon_rolleyes.pngicon_wink.pngicon_idea.pngicon_arrow.pngicon_neutral.pngicon_cry.pngicon_mrgreen.png