Home > Web Front-end > JS Tutorial > js method to simply display time on a web page_javascript skills

js method to simply display time on a web page_javascript skills

WBOY
Release: 2016-05-16 16:11:42
Original
1494 people have browsed it

The example in this article describes how to simply display time on a web page using js. Share it with everyone for your reference. The details are as follows:

This is a web clock JS code, implemented in pure javascript, which displays hours, minutes and seconds. There are many web time displays and web clocks. This one is really simple. Friends who are good at art can further beautify and improve it on this basis

Copy code The code is as follows:




Simple web clock

<script><br> window.onload = function ()<br> {<br> var oClock = document.getElementById("clock");<br> var aSpan = oClock.getElementsByTagName("span");<br> setInterval(getTimes, 1000);<br> getTimes();<br> function getTimes ()<br> {<br> var oDate = new Date();<br> var aDate = [oDate.getHours(), oDate.getMinutes(), oDate.getSeconds()];<br> for (var i in aDate) aSpan[i].innerHTML = format(aDate[i])<br> }<br> function format(a)<br> {<br> return a.toString().replace(/^(d)$/, "0$1")<br> }<br> }<br> </script>



PointsMinutesSeconds


I hope this article will be helpful to everyone’s JavaScript programming design.

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