setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式

 1 <script type="text/javascript">
 2             setInterval(function(){
 3                 var myDate = new Date();
 4                 var $_year = myDate.getFullYear();
 5                 var $_month = parseInt(myDate.getMonth())+1;
 6                 var $_day = myDate.getDate();
 7                 
 8                 var $_hour = myDate.getHours();
 9                 var $_minute = myDate.getMinutes();
10                 var $_second = myDate.getSeconds();
11                 
12                 if ($_hour < 10) {
13                     $_hour = "0" + $_hour;
14                 }
15                 if ($_minute < 10) {
16                     $_minute = "0" + $_minute;
17                 }
18                 if ($_second < 10) {
19                     $_second = "0" + $_second;
20                 }
21                 
22                 var $_f_date2 = $_year +"年"+$_month+"月"+$_day+"日"+" "+$_hour+":"+$_minute+":"+$_second;
23                 time.innerHTML = $_f_date2;
24             },1000)  //每过1秒运行一次
25             </script>

 

posted @ 2016-03-16 09:31  微明Axel  阅读(519)  评论(0编辑  收藏  举报