原生js写的一个当前年份日期星期和时间的显示

话不多说,所有代码如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>当前时间显示 </title>

</head>
<body onload="startTime()">
<div id="time"></div>
</body>
<script type="text/javascript">



function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()

var myyear=today.getFullYear();
var mymonth=today.getMonth();
var monthArray=["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"]
var mynowdate=today.getDate();
var myday=today.getDay();
var dayArray=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]


m=checkTime(m)
s=checkTime(s)
document.getElementById(time).innerHTML=myyear+""+monthArray[mymonth]+mynowdate+""+dayArray[myday]+h+":"+m+":"+s
setTimeout(startTime(),1000)
}

function checkTime(i)
{
if (i<10) 
  {i="0" + i}
  return i
}
</script>
</html>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。