当前位置:编程学习 > JS >>

请javascript高手帮写一个,天数自动加一的程序,每24小时就加一天,天数没有上线

补充:希望是显示 秒 分 时 天 和安全生产多少小时多少天一样。
答案:<html>
<body>
  <span id="safeD" style="width:200"></span>
  <span id="safeH" style="width:200"></span>
  <span id="safeM" style="width:200"></span>
  <span id="safeS" style="width:200"></span>
  <div id="times"></div>

<script type="text/javascript">
     var startTime = new Date(2010,01,01,00,00,00);//初始时间 2010-1-1 00:00:00
     var year;
     var month;
     var day;
     var hour;
     var minute;
     var seconds;
     var safeDay;
     var safeHour;
     var safeMinute;
     var safeSeconds;
     setInterval("addTime()",1000); //反复调用
     function addTime()
     {
         var timeNow = new Date();
         safeDay = parseInt((timeNow.getTime()-startTime.getTime())/(1000*60*60*24));
         safeHour = parseInt((timeNow.getTime()-startTime.getTime())/(1000*60*60));
         safeMinute = parseInt((timeNow.getTime()-startTime.getTime())/(1000*60));
         safeSeconds = parseInt((timeNow.getTime()-startTime.getTime())/1000);
         year = timeNow.getFullYear();
         month =timeNow.getMonth()+1;
         day = timeNow.getDate();
         hour = timeNow.getHours();
         minute = timeNow.getMinutes();
         seconds = timeNow.getSeconds();
         document.getElementById("safeD").innerHTML="安全生产天:"+safeDay;
	 document.getElementById("safeH").innerHTML="安全生产时:"+safeHour;
  	 document.getElementById("safeM").innerHTML="安全生产分:"+safeMinute;
	 document.getElementById("safeS").innerHTML="安全生产秒:"+safeSeconds;
	 document.getElementById("times").innerHTML="当前时间:"
               +year+"年"+month+"月"+day+"日"+hour+"时"+minute+"分"+seconds+"秒";
      }     
</script>

</body>
</html>
其他:......弄个时钟不就完了

上一个:自定义内容区是否支持javascript代码?
下一个:请教javascript、Java、C++、C的底层编程语言分别是什么?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,