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

js implements display time and date instance

小云云
Release: 2018-01-22 09:39:27
Original
1498 people have browsed it

This article mainly brings you an example of js displaying date and time (the time increases by 1 after one second). The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor to take a look, I hope it can help everyone.

html:

<p id="data"><font>2017年10月17日 15:11:11</font></span>
Copy after login

js:

1:Introducing js library

2:

function showLocale(objD) {  

 var str, colorhead, colorfoot;  

 var yy = objD.getYear();  

 if (yy < 1900) yy = yy + 1900;  var MM = objD.getMonth() + 1;  

 if (MM < 10) MM = &#39;0&#39; + MM;  var dd = objD.getDate();  

 if (dd < 10) dd = &#39;0&#39; + dd;  var hh = objD.getHours();  

 if (hh < 10) hh = &#39;0&#39; + hh;  var mm = objD.getMinutes();  

 if (mm < 10) mm = &#39;0&#39; + mm;  var ss = objD.getSeconds();  

 if (ss < 10) ss = &#39;0&#39; + ss;  var ww = objD.getDay();  

 if (ww == 0) colorhead = "";  

if (ww > 0 && ww < 7) colorhead = "";

str = colorhead + yy + "年" + MM + "月" + dd + "日 " + hh + ":" + mm + ":" + ss + " ";

return (str);

}

function tick() {

var today;

today = new Date();

document.getElementById("new_data").innerHTML = showLocale(today);

window.setTimeout("tick()", 1000);

}

tick();
Copy after login

Related recommendations:

Java uses regular expressions to implement time and date judgment operation analysis

Mysql method of automatically obtaining time and date

mysql How to automatically obtain the time and date examples

The above is the detailed content of js implements display time and date instance. For more information, please follow other related articles on the PHP Chinese website!

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!