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

JavaScript uses setInterval to implement days countdown and local time

黄舟
黄舟Original
2017-11-24 10:24:322142browse

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);

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!

Statement:
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