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('<input type=\"hidden\" name=\"wd\" type=\"text\" value=\"'+ (d.getMonth()+1)+'月'+d.getDate()+'日'+ '\">'); document.write(d.getFullYear()+'年'+(d.getMonth()+1)+'月'+d.getDate()+'日'+' 星期'+'日一二三四五六'.charAt(new Date().getDay()));</script>。 2018年高考时间:2018-06-07 9:00:00,距离考试还有<script type="text/javascript" language="javascript" > var bsDate=new Date('4/19/2018'); 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='danger'>"+startday+"</span>天"); }else{ } } getchaTime(); window.setInterval('getchaTime()',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:
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!