文件名:输入一个日期,返回星期的数字.html
文件代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>输入一个日期,返回星期的数字,例如输入的日期是2016-05-24 输出为 2</title>
<script language= "JavaScript">
function calcWeek(dt){
var da = (dt.replace(/-/g, "/")) // 把2016-05-24 转换为2016/05/24
var da= new Date(da) //接收的格式da为2016/05/24
var weekday=new Array(7)
weekday[0]=7
weekday[1]=1
weekday[2]=2
weekday[3]=3
weekday[4]=4
weekday[5]=5
weekday[6]=6
return weekday[da.getDay()]
}
//alert("时间 2016-05-24是周 :"+calcWeek('2016-05-24'));
function fn(){
var bb = calcWeek('2016-05-24')
return bb
}
alert(" "+fn());
</script>
</head>
<body>
</body>
</html>