本文實例為大家分享了4種js計算系統當前日期是星期幾的方法,供大家參考,具體內容如下
方法一:
// 計算系統當前是星期幾 var str = "今天是星期" + "日一二三四五六".charat(new date().getday());
方法二:
var a = new array("日", "一", "二", "三", "四", "五", "六"); var week = new date().getday(); var str = "今天是星期"+ a[week]; alert(str);
方法三:
var str = "今天是星期"; var week = new date().getday(); switch (week) { case 0 : str1 += "日"; break; case 1 : str1 += "一"; break; case 2 : str1 += "二"; break; case 3 : str1 += "三"; break; case 4 : str1 += "四"; break; case 5 : str1 += "五"; break; case 6 : str1 += "六"; break; } alert(str);
方法四:
var str = ""; var week = new date().getday(); if (week == 0) { str = "今天是星期日"; } else if (week == 1) { str = "今天是星期一"; } else if (week == 2) { str = "今天是星期二"; } else if (week == 3) { str = "今天是星期三"; } else if (week == 4) { str = "今天是星期四"; } else if (week == 5) { str = "今天是星期五"; } else if (week == 6) { str = "今天是星期六"; } alert(str);
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持。