Home > Web Front-end > JS Tutorial > JavaScript uses setInterval to implement days countdown and local time

JavaScript uses setInterval to implement days countdown and local time

黄舟
Release: 2017-11-24 10:24:32
Original
2241 people have browsed it

In our previous article, we introduced to you the detailed explanation of the use of setInterval in JavaScript. I believe that everyone has their own understanding of setInterval, so we will continue to give you this today Introducing the case of JavaScript using setInterval to implement days countdown and local time!

JavaScript uses setInterval to implement days countdown and local time

今天是<script type="text/javascript">var d = new Date(); 
document.write(&#39;<input type=\"hidden\" name=\"wd\" type=\"text\" value=\"&#39;+ (d.getMonth()+1)+&#39;月&#39;+d.getDate()+&#39;日&#39;+ &#39;\">&#39;); 
document.write(d.getFullYear()+&#39;年&#39;+(d.getMonth()+1)+&#39;月&#39;+d.getDate()+&#39;日&#39;+&#39; 星期&#39;+&#39;日一二三四五六&#39;.charAt(new Date().getDay()));</script>。
2018年高考时间:2018-06-07 9:00:00,距离考试还有<script type="text/javascript" language="javascript" >
var bsDate=new Date(&#39;4/19/2018&#39;);
function getchaTime()
{
var date = new Date();
var start =bsDate.getTime() - date.getTime();
var startday = Math.floor(start/(1000 * 60 * 60 * 24));
if(startday > 0){ document.write("<span class=&#39;danger&#39;>"+startday+"</span>天");
}else{
}
}
getchaTime();
window.setInterval(&#39;getchaTime()&#39;,3600000);
Copy after login

Today is Friday, November 24, 2017.
2018 College Entrance Examination Time: 2018-06-07 9:00:00, there are 194 days left until the exam

Summary:

Through the detailed study of this article, I believe that many friends will have a better understanding of the use of setInterval in JavaScript. I hope it will be helpful to your work!
Related recommendations:

Detailed explanation of the use of setInterval in JavaScript


JS implements scheduled tasks, requesting background setInterval timing and ajax requests every N seconds


JS SetInterval How to implement page polling tutorial

The above is the detailed content of JavaScript uses setInterval to implement days countdown and local time. 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