用js在网页上显示当前日期和时间,并显示是星期几
6个回答
展开全部
var date = new Date();
var weekDay = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
var week = weekDay[date.getDay()];
alert(year+","+month+","+day+","+week)
var weekDay = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
var week = weekDay[date.getDay()];
alert(year+","+month+","+day+","+week)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<div id="a"></div>
<script>
Number.prototype.getWeekName = function(){
switch(parseInt(this)){
case 0:
return "周日";
case 1:
return "周一";
case 2:
return "周二";
case 3:
return "周三";
case 4:
return "周四";
case 5:
return "周五";
case 6:
return "周六";
default:
return "unknow";
}
}
var x = setInterval(function(){
var d = new Date();
document.getElementById("a").innerText =
d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ", " + d.getDay().getWeekName();
}, 1000);
</script>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<HTML>
<HEAD>
<TITLE>我的第一个页面</TITLE>
<script type="text/javascript">
function showTime()
{
var time = new Date();
var year=time.getFullYear();
var month=time.getMonth()+1;
if(month<10)
{
month="0"+month;
}
var day=time.getDate();
if(day<10)
{
day="0"+day;
}
var hour=time.getHours();
if(hour<10)
{
hour="0"+hour;
}
var minute=time.getMinutes();
if(minute<10)
{
minute="0"+minute;
}
var second=time.getSeconds();
if(second<10)
{
second="0"+second;
}
var wd= time.getDay();
switch(wd)
{
case 0:
wd="星期日";
break;
case 1:
wd="星期一";
break;
case 2:
wd="星期二";
break;
case 3:
wd="星期三";
break;
case 4:
wd="星期四";
break;
case 5:
wd="星期五";
break;
case 6:
wd="星期六";
break;
}
document.timeform.timearea.value= year+"年"+month+"月"+day+"日"+" "+wd+" "+hour+":"+ minute+":"+second;
setTimeout("showTime()",1000);
}
</script>
<style type="text/css">
<!--
.STYLE1
{font-size: 36px;
color:#FF0000
}
</style>
</HEAD>
<BODY onLoad="showTime()">
<form name="timeform" method="POST" action="">
<table width="100%">
<tr>
<td colspan="2">
<p align="right">
<span class="STYLE1" align="right">现在时间是:</span> </td>
<td colspan="2">
<input name="timearea" type="text" size="30" align="middle" style="background-color:#ffffff;border:none;font-size:36px;color:#663333" readonly="readonly"></td>
</tr>
</table>
</form>
</BODY>
</HTML>
<HEAD>
<TITLE>我的第一个页面</TITLE>
<script type="text/javascript">
function showTime()
{
var time = new Date();
var year=time.getFullYear();
var month=time.getMonth()+1;
if(month<10)
{
month="0"+month;
}
var day=time.getDate();
if(day<10)
{
day="0"+day;
}
var hour=time.getHours();
if(hour<10)
{
hour="0"+hour;
}
var minute=time.getMinutes();
if(minute<10)
{
minute="0"+minute;
}
var second=time.getSeconds();
if(second<10)
{
second="0"+second;
}
var wd= time.getDay();
switch(wd)
{
case 0:
wd="星期日";
break;
case 1:
wd="星期一";
break;
case 2:
wd="星期二";
break;
case 3:
wd="星期三";
break;
case 4:
wd="星期四";
break;
case 5:
wd="星期五";
break;
case 6:
wd="星期六";
break;
}
document.timeform.timearea.value= year+"年"+month+"月"+day+"日"+" "+wd+" "+hour+":"+ minute+":"+second;
setTimeout("showTime()",1000);
}
</script>
<style type="text/css">
<!--
.STYLE1
{font-size: 36px;
color:#FF0000
}
</style>
</HEAD>
<BODY onLoad="showTime()">
<form name="timeform" method="POST" action="">
<table width="100%">
<tr>
<td colspan="2">
<p align="right">
<span class="STYLE1" align="right">现在时间是:</span> </td>
<td colspan="2">
<input name="timearea" type="text" size="30" align="middle" style="background-color:#ffffff;border:none;font-size:36px;color:#663333" readonly="readonly"></td>
</tr>
</table>
</form>
</BODY>
</HTML>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<script>
var mydate = new Date();
document.writeln("Year:"+mydate.getFullYear()+'<br>');
document.writeln("Month:"+(mydate.getMonth()+1)+'<br>');
document.writeln("Date:"+mydate.getDate()+'<br>');
document.writeln("Hours:"+mydate.getHours()+'<br>');
document.writeln("Minutes:"+mydate.getMinutes()+'<br>');
document.writeln("Seconds:"+mydate.getSeconds()+'<br>');
//星期几转成大写的
var weekDay = new Array('日','一','二','三','四','五','六');
var a = mydate.getDay()
document.writeln("WeekDay:"+weekDay[a]+'<br>');
// var str = "日一二三四五六".charAt(mydate.getDay());
// document.writeln("星期:" +str);
</script>
var mydate = new Date();
document.writeln("Year:"+mydate.getFullYear()+'<br>');
document.writeln("Month:"+(mydate.getMonth()+1)+'<br>');
document.writeln("Date:"+mydate.getDate()+'<br>');
document.writeln("Hours:"+mydate.getHours()+'<br>');
document.writeln("Minutes:"+mydate.getMinutes()+'<br>');
document.writeln("Seconds:"+mydate.getSeconds()+'<br>');
//星期几转成大写的
var weekDay = new Array('日','一','二','三','四','五','六');
var a = mydate.getDay()
document.writeln("WeekDay:"+weekDay[a]+'<br>');
// var str = "日一二三四五六".charAt(mydate.getDay());
// document.writeln("星期:" +str);
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询