JS计算系统当前日期是星期几的几种方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 :
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);
方法四:
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); 参考技术A (new Date()).getDay()
js中如何根据日期算出星期几
参考技术A <!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input id="y" type="text" placeholder="年" /> <input id="m" type="text" placeholder="月" />
<nput id="d" type="text" placeholder="日" /> <br /> <input type="button" id="btn" value="计算星期几" /> <input type="text"
id="w" placeholder="星期几">
<script>
var y = document.getElementById('y');
var m = document.getElementById('m');
var d = document.getElementById('d');
var w = document.getElementById('w');
var btn = document.getElementById('btn');
btn.onclick = function ()
var a = '';
a = y.value + '/' + m.value + '/' + d.value;
var date = new Date(a);
var week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
w.value = week[date.getDay()];
</script>
</body>
</script>
</body>
</html>
以上是关于JS计算系统当前日期是星期几的几种方法的主要内容,如果未能解决你的问题,请参考以下文章
presto sqlpresto sql 如何通过 计算当前日期(年月日,时分秒) 来计算当前是星期几?