如何在js里获取系统时间并在html中应用?
1个回答
展开全部
<div id='date'><script>getdates();</script></div>
<script language="javascript">
function getdates()
{
var w_array=new Array("星期天","星期一","星期二","星期三","星期四","星期五","星期六");
var d=new Date();
var year=d.getFullYear();
var month=d.getMonth()+1;
var day=d.getDate();
var week=d.getDay();
var h=d.getHours();
var mins=d.getMinutes();
var s=d.getSeconds();
if(month<10) month="0" + month
if(day<10) month="0" + day
if(h<10) h="0" + h
if(mins<10) mins="0" + mins
if(s<10) s="0" + s
var shows="现在时间是: <span>" + year + "-" + month + "-" + day + " " + h + ":" + mins + ":" + s + " " + w_array[week] + "</span>";
document.getElementById("date").innerHTML=shows;
setTimeout("getdates()",1000);
}
getdates();
</script>
<script language="javascript">
function getdates()
{
var w_array=new Array("星期天","星期一","星期二","星期三","星期四","星期五","星期六");
var d=new Date();
var year=d.getFullYear();
var month=d.getMonth()+1;
var day=d.getDate();
var week=d.getDay();
var h=d.getHours();
var mins=d.getMinutes();
var s=d.getSeconds();
if(month<10) month="0" + month
if(day<10) month="0" + day
if(h<10) h="0" + h
if(mins<10) mins="0" + mins
if(s<10) s="0" + s
var shows="现在时间是: <span>" + year + "-" + month + "-" + day + " " + h + ":" + mins + ":" + s + " " + w_array[week] + "</span>";
document.getElementById("date").innerHTML=shows;
setTimeout("getdates()",1000);
}
getdates();
</script>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询