重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
function clockon(clock){
创新互联主要从事网站设计制作、成都做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务襄城,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575
var bgclock = document.getElementById(clock);
var now = new Date();
var year = now.getYear();
var month = now.getMonth();
var date = now.getDate();
var day =now.getDay();
var hour = now.getHours();
var minu = now.getMinutes();
var sec = now.getSeconds();
var week;
month = month+1;
if(month10)month="0"+month;
if(date10)date="0"+date;
if(hour10)hour="0"+hour;
if(minu10)minu="0"+minu;
if(sec10)sec ="0"+sec;
var arr_week=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
week = arr_week[day];
var time=""
time=year+"年"+month+"月"+date+"日"+week+""+hour+":"+minu+":"+sec;
if(document.all){
bgclock.innerHTML="【"+time+"】"
}
var timer = setTimeout("clockon('bgclock')",200);
}
var myData = new Date(); // 是Date不是Data
var day = myData.getDay(); // 要括号
alert(day);
!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"
titleDocument/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
var a = new Array("日", "一", "二", "三", "四", "五", "六");
var dt = new Date(2014, 1, 1) 根据输入的值生成对象
var week = dt.getDay();
var str = "星期"+ a[week];
alert(str);
script type="text/javascript" language="javascript"
function calc(){
var date=new Date(),str;
week=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);
}
/script
注意我用的是alert对话框输出的值,new Date(),括号里面可以填指定日期,格式是:YYYY-MM-DD,注意加引号,如果new Date()后面的括号什么都不填,表示获取当前系统的日期和时间,date.getDay()这方法返回的是一个0到6之间的整数,0表示星期天,1到6表示星期一到星期六