<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>
一般一星期顺序如下:星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"
function getMyDay(date){
var week
if(date.getDay()==0) week="周日"
if(date.getDay()==1) week="周一"
if(date.getDay()==2) week="周二"
if(date.getDay()==3) week="周三"
if(date.getDay()==4) week="周四"
if(date.getDay()==5) week="周五"
if(date.getDay()==6) week="周六"
return week
}
var w1 = getMyDay(new Date("2015-7-12"))
JavaScript获取当前日期时间同时显示星期几,具体代码如下:<html>
<head>
<meta
http-equiv="Content-Type"
content="text/html
charset=utf-8"
/>
<script
type="text/javascript"
src="/jquery/1.7.0/jquery.min.js"></script>
<script
type="text/javascript">
function
currentTime(){
var
d=new
Date(),str=''
str+=d.getFullYear()+'年'
str+=d.getMonth()
+
1+'月'
str+=d.getDate()+'日'
str+=d.getHours()+'时'
str+=d.getMinutes()+'分'
str+=
d.getSeconds()+'秒'
return
str
}
setInterval(function(){$('#time').html(currentTime)},1000)
</script>
</head>
<body>
<div
id="time"></div>
</body>
</html>
在网页上及时动态显示当前的日期时间并显示星期的做法:
function
showTime(){
var
show_day=new
Array('星期一','星期二','星期三','星期四','星期五','星期六','星期日')
var
time=new
Date()
var
year=time.getYear()
var
month=time.getMonth()
var
date=time.getDate()
var
day=time.getDay()
var
hour=time.getHours()
var
minutes=time.getMinutes()
var
second=time.getSeconds()
month<10?month='0'+month:month
month=month+1
hour<10?hour='0'+hour:hour
minutes<10?minutes='0'+minutes:minutes
second<10?second='0'+second:second
var
now_time='当前时间:'+year+'年'+month+'月'+date+'日'+'
'+show_day[day-1]+'
'+hour+':'+minutes+':'+second
document.getElementById('showtime').innerHTML=now_time
setTimeout("showTime()",1000)
}
关于这方面的内容网上很多,有js获取当前日期时间同时显示星期,js获取当前时间和一星期钱的时间等内容,都很具有参考价值,希望大家多阅读类似文章,将类似方法熟练掌握。