您的位置:首页 > Web前端 > JavaScript

javascript实现动态日期和实时时钟

2013-09-07 09:36 369 查看
<html xmlns="http://www.w3.org/1999/xhtml">

  <head>

    <title>showtime</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

    <meta http-equiv="description" content="this is my page">

    <meta http-equiv="content-type" content="text/html; charset=gb2312">

    

    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
   function showtime(){
var today= new Date();
var year=today.getFullYear();
var month=today.getMonth()+1;
var date=today.getDate();
var day=today.getDay();
if(day==0){
day="日";
}else if(day==1){
day="一";
}else if(day==2){
day="二";
}else if(day==3){
day="三";
}else if(day==4){
day="四";
}else if(day==5){
day="五";
}else if(day==6){
day="六";
}
var hour =today.getHours();
if(hour<10){
hour="0"+hour;
}
var minute=today.getMinutes();
if(minute<10){
minute="0"+minute;
}
var second=today.getSeconds();
if(second<10){
second="0"+second;
}
document.getElementById("clock").innerHTML="<h1>现在是北京时间:"+year+"年"+month+"月"+date+"日    星期"+day+"    "+hour+":"+minute+":"+second+"</h1>"
var time=setTimeout("showtime()",1000);
}

    </script>

  </head>

  

  <body onload="showtime()">

<div id="clock"></div>   

  </body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript date time