Home > Web Front-end > JS Tutorial > body text

js实时获取系统当前时间实例代码_javascript技巧

WBOY
Release: 2016-05-16 17:30:59
Original
1253 people have browsed it

(1):首先用JS编写实时显示系统时间的函数 clockon() 只有一个参数bgclock,用于指定显示用于转化后的

标记的名称,无返回值,大家进行网站开发时可以将改函数保存在JS文件中,以便重用  代码如下:
复制代码 代码如下:

<script><BR>function clockon(bgclock)<BR>{<BR> var now = new Date();<BR> var year = now.getYear();<BR> var month = now.getMonth();<BR> var date = now.getDate();<BR> var day = now.getDay();<BR> var hour = now.getHours();<BR> var minu = now.getMinutes();<BR> var sec = now.getSeconds();<BR> var week;<BR> month = month+1;<BR> if(month<10)month="0"+month;<BR> if(date<10)date="0"+date;<BR> if(hour<10)hour="0"+hour;<BR> if(minu<10)minu="0"+minu;<BR> if(sec<10)sec="0"+sec;<BR> var arr_week = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");<BR> week = arr_week[day];<BR> var time = "";<BR> time = year+"年"+month+"月"+date+"日"+week+""+hour+";"+minu+";"+sec;<BR> if(document.all)<BR> {<BR> bgclock.innerHTML="["+time+"]"<BR> }<BR> var timer = setTimeout("clockon(bgclock)",200); <BR>}<BR></script>

(2):在页面的

的onload事件中 调用 以及在要显示的地方放置div标记  代码:
复制代码 代码如下:




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!